我需要呈现一个html表有精确的控制行,列,标题,样式等。
我是这样使用primeFaces panelGrid的:
<p:panelGrid binding="#{myBean.tableComponent}"/>
在我的支持bean中,我有:
private UIComponent tableComponent;
public UIComponent getTableComponent() {
if (tableComponent == null) {
tableComponent = new PanelGrid();
populateTableComponent(); // Populate datatable.
}
return tableComponent;
}
public void setTableComponent(UIComponent tableComponent) {
this.tableComponent = tableComponent;
}
private void populateTableComponent() {
PanelGrid tbl = (PanelGrid) tableComponent;
//...
for (MyPojo row : data.getRows) {
// ...here I create the row/column UIComponent subtree
}
}
现在,我的问题是:对于特定的列,我必须在每一行中呈现一个commandLink。
这个链接应该AJAX-调用一个bean的方法,它应该做一些与点击的行相关的事情。
像<p:commandLink action="#{myBean.myFieldClick(***row***)}">
这样的东西,但是
如何引用row
?
其他想法?
提前谢谢你
发布于 2012-11-07 01:30:25
只需使用与数据表的var
属性中定义的完全相同的变量名称即可。换句话说,写下与通常在视图文件中而不是在支持bean中编写时完全相同的EL表达式字符串。
因此,以下命令的action属性链接视图中的示例
<p:dataTable ... var="row">
...
<p:commandLink ... action="#{myBean.myFieldClick(row)}">
可以以编程方式表示为
MethodExpression action = createMethodExpression("#{myBean.myFieldClick(row)}", null, Row.class);
使用此帮助程序方法
public static MethodExpression createMethodExpression(String expression, Class<?> returnType, Class<?>... parameterTypes) {
FacesContext facesContext = FacesContext.getCurrentInstance();
return facesContext.getApplication().getExpressionFactory().createMethodExpression(
facesContext.getELContext(), expression, returnType, parameterTypes);
}
https://stackoverflow.com/questions/13255260
复制相似问题