I am trying to implement CRUD functionality in JSF/CDI.
I am stuck trying to implement edit functionality. I have an xhtml page that displays a list of Person entities in a datatable.
I want to place an edit link in the datatable for each person but I have completely forgotten how some of the mechanisms in JSF/CDI work. How do I pass the Person entity in the datatable to the Java code .?
do i do something like :
personList.xhtml
<h:datatable value="#{personList}" var="person">
<h:commandButton value="Go to edit page" action="#{personController.editPerson(person)"} />
</h:datatable>
personController.xhtml
@Named
@RequestScoped
public class PersonController {
//Person is a JPA entity so I can't inject it
Person editPerson;
public String editPerson(Person person) {
editPerson = person;
return "editPerson";
}
public String saveChanges(){
entityManager.merge(editPerson);
}
}
editPerson.xhtml
<h:form method="post">
<h:inputText value="#{personController.editPerson.name}" />
<h:commandButton value="Save Changes" action ="#{personController.saveChanges()}" />
</form>
After reading the link provided by BalusC I wanted to ask if there is not a better way than using a converter in conjunction with the tag to pass through the id?
I come from a Seam 2 background where Seam would automatically define the converters.Additionally that post doesn't make use of any CDI functionality...just Managed Beans..