JSF DataTable-特定记录 [英] JSF DataTable - particular record
问题描述
我有一个MySQL数据库.我仅使用一个名为USERS的表,该表具有以下列:用户ID,用户名,名称,年龄.我通过以下方式显示它们:
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>
(这是国际化的原因,因此#{lng.*})
(it is internationalized that's why are the #{lng.*})
我有2列带有图标的列,用于编辑和删除.我该怎么做才能使特定行上的用户ID传递给我的函数以进行删除和编辑?
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?
推荐答案
几乎没有方法
-
在JSF 2.0方法中,表达式可以带有参数
In JSF 2.0 method expressions can take parameters
<h:commandLink action="#{myBean.execute('hello')}"/>
要在动作方法中使用f:param标记,可以从参数映射中获取该值
To use f:param tag and inside of the action method you can get that value from parameters map
FaceContext.getCurrentInstance().getExternalContext().getRequestParametersMap()
使用f:setPropertyActionListener标记
To use f:setPropertyActionListener tag
这篇关于JSF DataTable-特定记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!