2
<h:dataTable value="#{studentBean2.studentList}" var="student">
    <h:column>
        <f:facet name="header">
            <h:outputText value="STUDENT-ID" />
         </f:facet>
         <h:outputText value="#{student.studentId}" />     
    </h:column>
    <h:column>
        <f:facet name="header">
            <h:outputText value="STUDENT-NAME" />
        </f:facet>
        <h:inputText value="#{student.studentName}" /> 
    </h:column>
    .........
    .........
</h:dataTable>
<h:commandButton type="submit" action="#{studentBean2.action}" value="ENTER" />

As from the above code, datatable values can be edited in <h:inputText> field and submitted. Those edited values are seen in action() method of bean StudentBean2.

As I followed the log, it showed that when I submit the page in the phase "Apply Request Values" the getStudentList() method is called. In this method I do the JDBC call to fetch students from the Database and set the newly fetched studentlist.

But in the "Invoke Application" phase, in method action() I get the edited data in the list which I have submitted. How exactly does this happen?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Rahul Shivsharan
  • 2,481
  • 7
  • 40
  • 59

1 Answers1

2

JSF has set them for you during the update model values phase. During this phase, the processUpdates() method of every component will be invoked. In case of the <h:dataTable> it's the UIData#processUpdates(). For every row it will then invoke the same method of the input component, which is in your case UIInput#processUpdates().

Basically:

get data model of UIData; // studentList = studentBean2.getStudentList()
for (every row of data model) {
    get the current row item by index; // student = studentList.get(index)
    for (every child UIInput component of UIData) {
        set its value; // student.setStudentName(value)
    }
}

Unrelated to the concrete problem, doing the JDBC call inside the getter method is a bad idea. The getter method will be called more than once during bean's life, so the JDBC call will be unnecessarily made too many times. You should make the JDBC call in bean's (post)constructor instead. See also Why JSF calls getters multiple times.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555