0

I pre-populate a JSF form with information about a teacher taken from a database. Then when this information is changed in the input fields I want to update it in the database when clicking the "Submit" button. How can I pass the teacher object teachersBean.teacher to the action attribute, so that I get the object and it's properties set with their new values and save them in the TeachersBean's teacher object. I tried action="#{teachersBean.updateTeacher(teachersBean.teacher)}", but it doesn't seem to be the right way.

I have the class TeacherBean, which has Teacher teacher field. The class Teacher has firstname, lastname and address, which are Strings. So I want to fill out the form with new information (i.e. teachersBean.teacher.firstname, teachersBean.teacher.lastname, teachersBean.teacher.address) and pass the whole object to the action method. I need something like in the dataTable tag, where I can set a var="user" and can pass it like that action="#{teachersBean.updateTeacher(user)}"

I have this form in JSF:

<h:form>
        <h:panelGroup layout="block">
            <h:outputLabel value="Name: " />
            <h:inputText value="#{teachersBean.teacher.firstname}" />
        </h:panelGroup>

        <h:panelGroup layout="block">
            <h:outputLabel value="Last name: " />
            <h:inputText value="#{teachersBean.teacher.lastname}" />
        </h:panelGroup>

        <h:panelGroup layout="block">
            <h:outputLabel value="Address: " />
            <h:inputText value="#{teachersBean.teacher.address}" />
        </h:panelGroup>

        <h:panelGroup layout="block">
            <h:commandButton value="Submit" styleClass="newEntry"
                action="#{teachersBean.updateTeacher}">
            </h:commandButton>
        </h:panelGroup>
    </h:form>
ikken32
  • 103
  • 9

0 Answers0