Jacob
Jacob

Reputation: 14731

JSF databatable selected row

This may sound quite strange, but checking whether any possibilities are there to get datatable selected row value if action is not in datatable row.

I have the following in JSF page

    <p:dataTable id="det" var="emp" lazy="true"
value="#{myMB.lazyModel}" paginator="true"
paginatorPosition="bottom" rows="10"
    rowKey="#{emp.employeeNumber}">

    <f:facet name="header">                  
        Employee Details    
    </f:facet>

If I add the following inside <p:column> </p:column> I am able to get the selectedDepartment row in ManagedBean, but if I add button above <p:column> </p:column>, i.e. not in datatable row, but on the heading, I am not able to get the selectedDepartment row because it is not in datatable row.

Are there any way I can get the selectedDepartment row if I add a button not in datatable row?

             <p:commandButton id="addEmployee" 
              icon="ui-icon-plus"                          
              oncomplete="newEmployeeDialog.show()" >
     <f:setPropertyActionListener value="#{emp}" 
     target="#{myMB.selectedDepartment}" />   
      </p:commandButton>

Upvotes: 1

Views: 204

Answers (1)

erhanasikoglu
erhanasikoglu

Reputation: 1735

I don't think you can get the info like rowId if you dont put button inside the row. I suggest you first get an id from dataTable then take it into any hidden value to use it in commandButton.

Upvotes: 1

Related Questions