如何获取当前行 p:dataTable 素数的 ID 到我的链接中使用此 Id?描述一下(对不起我的英语)。我的数据表如下图所示:
http://www.image-share.com/igif-2333-105.html 当我单击按钮时,我想获取此按钮所在的行的 ID,例如第 1 行的 id 为 1,因此当单击按钮 1 时,我必须获取 ID = 1。在需要 id 的地方显示我的链接的外观:
http://'serverAddress'/myApplication/PDF?type=document&id="+id"
变量 id 具有 int 和 getters 类型,实体和 bean 中的 setter。JSF 中的按钮如下所示:
h:commandButton value="Print" action="#{printBean.print()}"/>
方法"打印"启动我的链接。任何想法如何做到这一点?感谢您的帮助。
p:dataTable
的rowIndexVar
属性。
要引用每个行索引的迭代器的名称
可以在 EL 中使用其迭代器名称来获取行 ID
例如:如果rowIndexVar="myId"
则您可以使用 EL 中的迭代器名称访问每一行索引,使用 #{myID}
。
例:
<p:dataTable rowIndexVar="rowId" value="..." var="...">
<p:column>
<h:commandLink action="#{...}">
<f:param name="id" value="#{rowId}" />
</h:commandLink>
</p:column>
</p:dataTable>
在 bean 中获取id
map<String,String> par_map = new HashMap<String,String>(); par_map=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String id=par_map.get("id");