datatable row selected unselected in primefaces

<p:dataTable id=”menusTable” var=”menu”

value=”#{menuManager.resultMenus}” rowKey=”#{}” paginator=”true”

rowClasses=”odd, even” rows=”5″

rowsPerPageTemplate=”5, 10, 15, 25, 50, 100″

paginatorTemplate=” {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} ”

sortBy=”#{}” selection=”#{menuManager.selectedMenu}”


<p:ajax event=”rowSelect” listener=”#{menuManager.onRowSelect}”/>


if we have the selection mapped to a field in the service bean like the red part above, the datatable would always remember our last selection. The problem of it is we will not be able to select that row again if user navigate back to the page.

The solution is remove that red part.

in the  onRowSelect() method add:  selectedMenu = (Menu)event.getObject();

This way, problem solved.


another way would be manually NULL that selectedMenu in bean code after all the business logic if you really want to keep that red part. if you still need to use this selectedMenu in some other page, this way should not be used.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s