Can not pass object to dialog

UI Components for JSF
Post Reply
max
Posts: 28
Joined: 17 Nov 2010, 15:55

21 Feb 2011, 17:55

I am using showcase datatable row select example, when user selects a record, it pop ups a dialog to display the detials.
I used <f:setPropertyActionListener value="#{e}" target="#{employeeController.selectedEmployee}" /> to pass employee object to the dialog
But on the dialog, the selectedEmployee record is empty. (I have update="display" in the dialog). Can anyone help?

Thanks
max

Here is my employee.xhtml
<ui:composition template="/WEB-INF/template/layout.xhtml">
<ui:define name="content">
<p:messages />
<h:form id="employeeForm">

<p:dataTable var="e" value="#{employeeController.employees}" rowEditListener="#{employeeController.employeeRowEdit}">
<p:column headerText="Name" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{e.name}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{e.name}" style="width:100%" valueChangeListener="#{employeeController.nameChanged}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Contacts" style="width:32px">
<p:commandButton update="display" oncomplete="contactDialog.show()" image="ui-icon ui-icon-search">
<f:setPropertyActionListener value="#{e}" target="#{employeeController.selectedEmployee}" />
</p:commandButton>
</p:column>
<p:column style="width:32px">
<p:rowEditor id="employeeRow"/>
</p:column>

<p:dialog header="Contact" widgetVar="contactDialog" showEffect="explode" hideEffect="explode">
<h:panelGrid id="display" columns="2" cellpadding="4">
<h:outputText value="Name:" />
<h:outputText value="#{employeeController.selectedEmployee.name}" />
</h:panelGrid>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>

Here is my EmployeeController bean Constructor
@ManagedBean
@SessionScoped
public class EmployeeController implements Serializable{

private static final long serialVersionUID = 1L;

private List<Employee> employees;
private Employee selectedEmployee;

public EmployeeController() {

this.employees = new ArrayList<Employee>();
ArrayList<Contact> cs1 = new ArrayList<Contact>();
cs1.add(new Contact("x@abc.com"));
cs1.add(new Contact("y@abc.com"));
Employee e1 = new Employee("1", "John", "MO", cs1);

ArrayList<Contact> cs2 = new ArrayList<Contact>();
cs2.add(new Contact("a@abc.com"));
cs2.add(new Contact("b@abc.com"));
Employee e2 = new Employee("2", "Peter", "MT", cs2);

this.employees.add(e1);
this.employees.add(e2);
}
All getters and setters are there.

max
Posts: 28
Joined: 17 Nov 2010, 15:55

22 Feb 2011, 01:28

I found why. I need to put prependId="false" in the form.

Thanks

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 31 guests