Binding 在jsf2中,如何呈现一个带有引用后台bean中的POJO的操作的commandLink?
我需要呈现一个对行、列、标题、样式等进行精确控制的html表。Binding 在jsf2中,如何呈现一个带有引用后台bean中的POJO的操作的commandLink?,binding,jsf-2,Binding,Jsf 2,我需要呈现一个对行、列、标题、样式等进行精确控制的html表。 我使用primeFaces panelGrid的方式如下: <p:panelGrid binding="#{myBean.tableComponent}"/> 现在,我的问题是: 对于特定列,我必须在每行中呈现一个commandLink。 此链接应调用bean的方法,该方法应执行与单击行相关的操作。 类似于但 我如何参考行 其他想法 提前谢谢只需使用与数据表的var属性中定义的变量名完全相同的变量名即可。换句话说,写下
我使用primeFaces panelGrid的方式如下:
<p:panelGrid binding="#{myBean.tableComponent}"/>
现在,我的问题是:
对于特定列,我必须在每行中呈现一个commandLink。此链接应调用bean的方法,该方法应执行与单击行相关的操作。
类似于
但我如何参考
行
其他想法
提前谢谢只需使用与数据表的
var
属性中定义的变量名完全相同的变量名即可。换句话说,写下完全相同的EL表达式字符串,就像通常在视图文件中而不是在后台bean中写它时一样
因此,以下命令链接示例的action属性在视图中
<p:dataTable ... var="row">
...
<p:commandLink ... action="#{myBean.myFieldClick(row)}">
使用此助手方法
public static MethodExpression createMethodExpression(String expression, Class<?> returnType, Class<?>... parameterTypes) {
FacesContext facesContext = FacesContext.getCurrentInstance();
return facesContext.getApplication().getExpressionFactory().createMethodExpression(
facesContext.getELContext(), expression, returnType, parameterTypes);
}
publicstaticmethodexpression createMethodExpression(字符串表达式、类returnType、类…参数类型){
FacesContext FacesContext=FacesContext.getCurrentInstance();
返回facesContext.getApplication().getExpressionFactory().createMethodExpression(
facesContext.getELContext(),表达式,返回类型,参数类型);
}
谢谢你,巴卢斯克。但是,如果我理解正确,这应该适用于dataTable
。这里我没有var
属性,因为迭代在支持bean代码中。(如果我调用变量“tableComponent”,很抱歉,但它是一个panelGrid
)
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);
}