开发者

JSF DataTable - particular record [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How can I 开发者_开发百科pass a parameter to a commandLink inside a datatable?

I have a MySQL database. I use only one table called USERS which has columns: userid, username, name, age. I display them by:

<h:dataTable 
    var="my_user"   
    value="#{user.users}"
    border="1"
    styleClass="mainTable"
    headerClass="heading"
    rowClasses="evenRow, oddRow, "
    id="rend">

    <h:column>
        <f:facet name="header">#{lng.userId}</f:facet>
        <h:outputText value="#{my_user.userId}" />
    </h:column>
    <h:column>
        <f:facet name="header">#{lng.username}</f:facet>
        <h:outputText value="#{my_user.username}" />
    </h:column>
    <h:column>
        <f:facet name="header">#{lng.name}</f:facet>
        <h:outputText value="#{my_user.name}" />
    </h:column>
    <h:column>
        <f:facet name="header">#{lng.age}</f:facet>
        <h:outputText value="#{my_user.age}" />
    </h:column>
    <h:column>
        <f:facet name="header">#{lng.edit}</f:facet>
        <h:graphicImage name="edit.png" library="images" styleClass="tableIcon">
            <f:ajax event="click" listener="#{someClass.edit}" render="rend"/>
        </h:graphicImage>
    </h:column>
    <h:column>
        <f:facet name="header">#{lng.del}</f:facet>
        <h:graphicImage name="delete.png" library="images" styleClass="tableIcon">
            <f:ajax event="click" listener="#{someClass.delete}" render="rend"/>
        </h:graphicImage>
    </h:column>
</h:dataTable>

(it is internationalized that's why are the #{lng.*})

I have 2 columns with icons for edit and delete. What should I do to get the ID of a user on particular row to pass to my functions for delete and edit?


There are few possible ways how to do that

  • In JSF 2.0 method expressions can take parameters

    <h:commandLink action="#{myBean.execute('hello')}"/>
    
  • To use f:param tag and inside of the action method you can get that value from parameters map

    FaceContext.getCurrentInstance().getExternalContext().getRequestParametersMap()
    
  • To use f:setPropertyActionListener tag

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜