Exact semantics of getRowData ()?

First time using JSF, and I'm a bit confused about how it works getRowData(). All I found when searching on the Internet was that it returns the “current selected row” in the data table, but I could not find out how it determines which row is selected. For example, I have this code for a data table:

JSP:

  <h:dataTable value="#{backing_student.eligibleCoursesList}" var="cdto"
                     binding="#{backing_student.eligibleCoursesDataTable}"
                     id="eligibleCoursesDataTable" rules="all" frame="box"
                     border="2">
  <%-- 
            oracle-jdev-comment:Faces.RI.DT.Class.Key:hu.elte.pgy2.BACNAAI.UranEJB.CourseDTO
          --%>
    <h:column>
      <f:facet name="header">
        <h:outputText value="Kurzuskód"
                      binding="#{backing_student.outputText7}"
                      id="outputText7"/>
      </f:facet>
      <h:outputText value="#{cdto.cid}"/>
    </h:column>
    <!-- couple more plain text columns like the above -->
    </h:column>
    <h:column>
      <h:commandButton value="Felvétel"
                       actionListener="#{backing_student.addSelfToCourseListener}"/>
    </h:column>
  </h:dataTable>

Bean support:

public class BackingStudent {
    private HtmlDataTable eligibleCoursesDataTable;
    private List<CourseDTO> eligibleCoursesList;

    // ...

    public void addSelfToCourseListener(ActionEvent actionEvent) {
        HtmlCommandButton thisButton = (HtmlCommandButton)actionEvent.getComponent();
        CourseDTO cdto = (CourseDTO)(eligibleCoursesDataTable.getRowData());
        thisButton.setValue(cdto.getCid());
    }
}

This makes it so that whenever I press a button on any row, the text of all buttons changes to the value in the first column of that row. How to getRowData()know exactly which row to select from the table?

Bonus question: why does every button text change?

+3
source share
2 answers

JSF . , dataTable UIData ( HtmlDataTable ). UIData , DataModel. JSF - :

//not the real code
for(int i=0; i<model.getRowCount(); i++) {
  model.setRowIndex(i);
  Object row = model.getRowData();
  externalContext.getRequestMap().put(var, row);
  //invoke phase-specific action
  externalContext.getRequestMap().remove(var);
}

var="cdto", , EL bean, .

, UIData . . UIData , ( ) HtmlCommandButton, EditableValueHolder.

, EL (, row bean).

. , javax.faces... beans, .

+3

, DataModel.setRowIndex(), . DataModel.getRowData() , DataModel.getRowIndex().

+1

Source: https://habr.com/ru/post/1773504/


All Articles