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
JSF/PrimeFaces:编程<;f:setPropertyActionListener>;on<;p:commandButton>;不开火_Jsf_Jsf 2_Primefaces_Datatable_Commandbutton - Fatal编程技术网

JSF/PrimeFaces:编程<;f:setPropertyActionListener>;on<;p:commandButton>;不开火

JSF/PrimeFaces:编程<;f:setPropertyActionListener>;on<;p:commandButton>;不开火,jsf,jsf-2,primefaces,datatable,commandbutton,Jsf,Jsf 2,Primefaces,Datatable,Commandbutton,我们要求允许用户在所有数据表中配置列的顺序,包括上面有操作按钮的列,这里是p:commandButtons 因此,我们对所有列使用绑定,必须手动实例化。对于只显示一些字符串、布尔值、日期和数字的所有列,所有这些都可以正常工作,但是在将p:commandButtons添加到包含一个或多个s的列时会出现问题 ELContext elContext = FacesContext.getCurrentInstance().getELContext(); ExpressionFactory

我们要求允许用户在所有数据表中配置列的顺序,包括上面有操作按钮的列,这里是
p:commandButton
s

因此,我们对所有列使用绑定,必须手动实例化。对于只显示一些字符串、布尔值、日期和数字的所有列,所有这些都可以正常工作,但是在将
p:commandButton
s添加到包含一个或多个
s的列时会出现问题

    ELContext elContext = FacesContext.getCurrentInstance().getELContext();
    ExpressionFactory factory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();

    CommandButton button = new CommandButton();
    button.setIcon( "ui-icon ui-icon-pencil" );
    button.setProcess( "@this" );
    button.setUpdate( ":compliance-case-dialog :compliance-case-form:data" );
    button.setOncomplete( "complianceCaseDialog.show();" );

    ValueExpression targetExpression = factory.createValueExpression( elContext, "#{complianceCaseManager.selectedComplianceCaseWithRefresh}", ComplianceCase.class );
    ValueExpression valueExpression = factory.createValueExpression( elContext, "#{coca}", ComplianceCase.class );

    button.addActionListener( new SetPropertyActionListenerImpl( targetExpression, valueExpression ) );

    column.getChildren().add( button ); // add to Column instance
此按钮“正确”显示数据表的当前实体(由
var=“coca”
定义)的
ComplianceCaseManager
类“
setSelectedComplianceCaseWithRefresh(ComplianceCase selectedComplianceCase)
方法,然后显示对话框

<p:dataTable id="data"
             widgetVar="resultTable"
             value="#{complianceCaseManager.complianceCases}"
             var="coca"
             ...>
</p:dataTable>
线路

    <f:setPropertyActionListener target="#{complianceCaseManager.selectedComplianceCaseWithRefresh}" value="#{coca}" />
创建AFAIK是为了在目标上调用setter,在值上调用setter,因此我假设
ValueExpression
s就足够了


更新2:

试图通过EL 2.2方法调用设置当前实体也不起作用

代码:

String方法ExpressionString=“#”+“{complianceCaseManager.selectedComplianceCaseWithRefresh(coca)}”;
MethodExpression MethodExpression=factory.createMethodExpression(elContext,methodExpressionString,null,新类[]{ComplianceCase.Class});
addActionListener(新的MethodExpressionActionListener(methodExpression));
什么都不叫


更新3:

以下是正确的
代码:

    // traditional <f:setPropertyActionListener target="#{complianceCaseManager.selectedComplianceCaseWithRefresh}" value="#{coca}" />
    ValueExpression targetExpression = factory.createValueExpression( elContext, "#{complianceCaseManager.selectedComplianceCaseWithRefresh}", ComplianceCase.class );
    ValueExpression valueExpression = factory.createValueExpression( elContext, "#{coca}", ComplianceCase.class );

    button.addActionListener( new SetPropertyActionListenerImpl( targetExpression, valueExpression ) );
//传统的
ValueExpression targetExpression=factory.createValueExpression(elContext,“{complianceCaseManager.selectedComplianceCaseWithRefresh}”,ComplianceCase.class);
ValueExpression ValueExpression=factory.createValueExpression(elContext,“{coca}”,ComplianceCase.class);
addActionListener(新的SetPropertyActionListenerImpl(targetExpression,valueExpression));

非常感谢科洛索斯。当实例化PrimeFaces
CommandButton
时,请记住调用
setId()
,actionListener应创建为
MethodExpression
而不是
ValueExpression

  • 我假设ExpressionFactory的工厂实例是
    。使用

  • 将侦听器添加到组件:

    button.addActionListener( new MethodExpressionActionListener(targetExpression));
    
  • 与当前问题不完全相关,您还省略了组件的
    id
    属性。为了安全起见,添加

    button.setId("theButton");
    
    编辑:在动态创建命令组件时,必须设置
    id
    属性


  • 我曾经使用lambda表达式来解决这个问题:

    private final ActionListener actionListener = (ActionEvent event) -> {
                //code to execute
            };
    
    然后就是:

  • 设置命令按钮id
    comandButton.setId(id)
  • 添加de ActionListener
    commandButon.addActionListener(ActionListener)

  • 它不能工作。根据和Java文档,
    SetPropertyActionListenerImpl
    构造函数的签名是
    com.sun.faces.taglib.jsf_core.SetPropertyActionListenerImpl.SetPropertyActionListenerImpl(ValueExpression目标,ValueExpression值)
    MethodExpression
    不继承自
    ValueExpression
    ,仅继承
    Expression
    。这可能是使用直接EL 2.2方法调用的最后手段。然而,我想知道如何将“老派”JSF1.2
    s翻译成编程变体。查看我的更新以查看普通JSF中的
    。您是否设置了
    id
    属性?OMG.:-哦,这真的解决了!请将其作为答案发布。:-)它已经在那里了:)谢谢你的帮助。
    MethodExpression targetExpression = factory.createMethodExpression( elContext, "#{complianceCaseManager.selectedComplianceCaseWithRefresh(coca)}",null,new Class[]{ComplianceCase.class} );
    
    button.addActionListener( new MethodExpressionActionListener(targetExpression));
    
    button.setId("theButton");
    
    private final ActionListener actionListener = (ActionEvent event) -> {
                //code to execute
            };