Time for action – passing data from the search users dialog to the source page
Let us add a new column Select
to the DataTable
in the searchUsers.xhtml
page to select a user, and pass the selected user's details back to source page. Perform the following steps:
Create a
DataTable
component with aSelect
column to choose a user row using the following code:<p:dataTable id="usersTbl" value="#{userController.searchUsers}" var="user"> <p:column headerText="EmailId"> #{user.emailId} </p:column> <p:column headerText="Name"> #{user.firstName} #{user.lastName} </p:column> <p:column headerText="Select"> <p:commandButton icon="ui-icon-search" actionListener="#{userController.selectSearchUser(user)}" /> </p:column> </p:dataTable>
When the user selects a row (user), close the dialog by passing the selected
user
object as data:public void selectSearchUser(User user){ RequestContext.getCurrentInstance().closeDialog(user); }
Register...