Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Binding 在jsf2中,如何呈现一个带有引用后台bean中的POJO的操作的commandLink?_Binding_Jsf 2 - Fatal编程技术网

Binding 在jsf2中,如何呈现一个带有引用后台bean中的POJO的操作的commandLink?

Binding 在jsf2中,如何呈现一个带有引用后台bean中的POJO的操作的commandLink?,binding,jsf-2,Binding,Jsf 2,我需要呈现一个对行、列、标题、样式等进行精确控制的html表。 我使用primeFaces panelGrid的方式如下: <p:panelGrid binding="#{myBean.tableComponent}"/> 现在,我的问题是: 对于特定列,我必须在每行中呈现一个commandLink。 此链接应调用bean的方法,该方法应执行与单击行相关的操作。 类似于但 我如何参考行 其他想法 提前谢谢只需使用与数据表的var属性中定义的变量名完全相同的变量名即可。换句话说,写下

我需要呈现一个对行、列、标题、样式等进行精确控制的html表。
我使用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);
}