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>
</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?
source
share