【问题标题】:JSF 2.0 HTMLCommandButton doesn't call ActionListener in Custom ComponentJSF 2.0 HTMLCommandButton 不在自定义组件中调用 ActionListener
【发布时间】:2013-07-17 13:34:53
【问题描述】:

我目前正在 JBoss AS 7.1 上开发一个带有纯 JSF 的 PopUp,并且我正在尝试在弹出类的渲染器中添加一个命令按钮。 Popup 类扩展了 UIPanel。 弹出窗口位于 h:form 内。

将按钮添加到弹出窗口的代码:

private static final String ID_FIELD_TAG = "id";
private static final String HTML_DIV_TAG = "div";

[...]

writer.startElement(HTML_DIV_TAG, component);
writer.writeAttribute(ID_FIELD_TAG, konstanten.getPopupFooterId(), ID_FIELD_TAG);
writer.write("\n");
if(popup.isShowDialogButtons()){
    HtmlCommandButton cancelButton = new HtmlCommandButton();
    component.getChildren().add(cancelButton);
    cancelButton.setId(konstanten.getPopupFooterCancelButtonId());
    cancelButton.setValue(popup.getCancelText());
    if (!popup.getCancelAction().equals("")) {
        String expression = "#{"+popup.getCancelAction()+"}";
        MethodExpression methodExpression = ExpressionHelper.EXPRESSION_HELPER.
            generateMethodExpression(expression, null,
                new Class<?>[] { ActionEvent.class });
        cancelButton.addActionListener(new MethodExpressionActionListener(
            methodExpression));
    } else {
        cancelButton.setOnclick("hidePopup('" + componentId + "')");
    }
    cancelButton.encodeAll(context);
}
writer.endElement(HTML_DIV_TAG);

按钮是可见的,但点击它时什么也没有发生,除了页面重新加载。

popup.getCancelAction() 返回“NameOfTheBean.NameOfTheMethod”。

没有错误消息。

感谢您的帮助!

编辑: 我尝试用 HTMLCommandLink 替换 HTMLCommandButton 以查看表单是否存在问题。该链接看起来可以正常工作,但仍然没有调用任何内容。

【问题讨论】:

  • 我改变了方法,所以它使用了一个直接的ActionListener,它应该只打印“action”,但这也不起作用。没人知道吗?

标签: java jsf-2 jboss custom-component


【解决方案1】:

问题是,按钮没有正确添加到 JSF 组件树中。我已将它们作为子组件添加到组件中,并在 encodeChildren() 方法中忽略它们。

如果有人知道更好的解决方案,我很想知道,所以请不要犹豫回答这个问题!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-11
    • 2012-06-27
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 2011-11-11
    相关资源
    最近更新 更多