【问题标题】:Add action dynamically to commandButton将动作动态添加到 commandButton
【发布时间】:2023-03-07 08:34:01
【问题描述】:

我正在使用 JSF 2.0 和 tomahawk-lib 动态创建 html 元素。我想向 HtmlCommandButton 添加一个操作命令,但无法完成。在此先感谢您的帮助。我可以看到按钮和onclick被触发了,所以一定是方法表达式的错误。

HtmlCommandButton submitLogin = new HtmlCommandButton();
FacesContext fc = FacesContext.getCurrentInstance();
ELContext ctx = fc.getELContext();
String expression = "#{hangmanController.login}";
Class[] parameterTypes = new Class[0];
MethodExpression me = fc.getApplication().getExpressionFactory().
     createMethodExpression(ctx, expression, String.class, parameterTypes);
submitLogin.setActionExpression(me);
submitLogin.setOnclick("alert('BP');");

【问题讨论】:

    标签: jsf tomahawk


    【解决方案1】:

    以编程方式创建的UIInputUICommand 组件必须具有固定的 ID 集,否则 JSF 将在应用请求值阶段无法识别与请求参数映射中的输入和命令组件关联的请求参数。

    submitLogin.setId("submitLogin");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-20
      • 2021-11-03
      • 2016-08-02
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      • 2013-07-16
      • 1970-01-01
      相关资源
      最近更新 更多