0

Please find my code below for p:datatable having h:commandlink as one of its column:

   <p:dataTable id="listTable" value="#{listBean.lazyDatalist}"
                         var="list" paginator="true" paginatorPosition="top" rows="10"
                         rowIndexVar="rowIndex" 
                        rowStyleClass="#{(rowIndex mod 2) eq 0 ? 'rowStyleOdd' : 'rowStyleEven'}" 
                        lazy="true">
                        <p:ajax event="page" listener="#{listBean.searchLazyData}"/>
                        <p:column style="width:3%;" headerText="#{msg['userlist.dt.srNo']}">
                            <h:outputText value="#{list.orderCount}"></h:outputText>
                        </p:column>                 
                        <p:column  style="width:7%;"
                            headerText="#{msg['userlist.dt.EmployeeID']}">
                        <h:outputText value="#{list.employeeID}"/>  
                        </p:column>
                        <p:column  style="width:12%;"
                            headerText="#{msg['userlist.dt.Name']}">
                        <h:outputText value="#{list.employeeName}"></h:outputText>  
                        </p:column>
                        <p:column headerText="#{msg['userlist.dt.actionReq']}">
                                <h:commandLink value="#{list.actionRequired}" action="#{listBean.getDetails}" styleClass="linkStyle"></h:commandLink>                       
                        </p:column>
                    </p:dataTable>

I want to access the datatable row in Backing Bean ListBean for which h:commandLink is clicked using action="#{listBean.getDetails}" without using datatable binding attribute.

My Backingbean is session scoped and we are using jsf 2.1.7 Mojarra.

Kai
  • 38,985
  • 14
  • 88
  • 103
Viniti
  • 125
  • 2
  • 9

3 Answers3

3

But MOST of all, Take a look at the first selection example in the PrimeFaces showcase http://www.primefaces.org/showcase/ui/data/datatable/selection.xhtml

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • And please search for duplicates – Kukeltje Jun 02 '15 at 07:06
  • Thanks :) But I want to use commandLink specifically and in primefaces all datatable selection features have commandButton. please help. – Viniti Jun 02 '15 at 07:14
  • May I suggest to take a step back and learn some of the basics of jsf http://stackoverflow.com/questions/10688755/hcommandbutton-vs-hcommandlink – Kukeltje Jun 02 '15 at 07:48
0

Pass the selected row as parameter to your method such as

<h:commandLink value="#{list.actionRequired}" action="#{listBean.getDetails(list)}" styleClass="linkStyle"></h:commandLink> 

and change getDetails to accept a parameter of element type of listBean.lazyDatalist

Smutje
  • 17,733
  • 4
  • 24
  • 41
  • I tried the same but not able to pass parameter in action attribute. – Viniti Jun 02 '15 at 07:09
  • 1
    "not able to pass" - have you ever passed a parameter to a method called by JSF? If not, you better learn that first. – Smutje Jun 02 '15 at 07:11
0

var contains the object which is used to fill each row. You can just pass it in your action like #{listBean.getDetails(list)}. Don´t forget to add this parameter to your bean method.

By the way: list is very misleading. You should better name it element or with it´s concrete entity name, maybe employee. Your team will be grateful.

Kai
  • 38,985
  • 14
  • 88
  • 103
  • Not able to pass parameter in action attribute. getting error in eclipse as "Syntax error in EL". Please help. – Viniti Jun 02 '15 at 07:12