Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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

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
Java JSF2.0 HTMLCommandButton不';t在自定义组件中调用ActionListener_Java_Jsf 2_Jboss_Custom Component - Fatal编程技术网

Java JSF2.0 HTMLCommandButton不';t在自定义组件中调用ActionListener

Java JSF2.0 HTMLCommandButton不';t在自定义组件中调用ActionListener,java,jsf-2,jboss,custom-component,Java,Jsf 2,Jboss,Custom Component,我目前正在JBoss AS 7.1上开发一个带有普通JSF的弹出窗口,并试图在弹出窗口类的呈现器中添加一个命令按钮。类弹出窗口扩展了UIPanel。 弹出窗口位于一个h:窗体内 将按钮添加到弹出窗口的代码: private static final String ID_FIELD_TAG = "id"; private static final String HTML_DIV_TAG = "div"; [……] writer.startElement(HTML\u DIV\u标记,组件); w

我目前正在JBoss AS 7.1上开发一个带有普通JSF的弹出窗口,并试图在弹出窗口类的呈现器中添加一个命令按钮。类弹出窗口扩展了UIPanel。 弹出窗口位于一个h:窗体内

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

private static final String ID_FIELD_TAG = "id";
private static final String HTML_DIV_TAG = "div";
[……]

writer.startElement(HTML\u DIV\u标记,组件);
writeAttribute(ID\u FIELD\u标记,konstanten.getPopupFooterId(),ID\u FIELD\u标记);
writer.write(“\n”);
if(popup.isShowDialogButtons()){
HtmlCommandButton cancelButton=新建HtmlCommandButton();
component.getChildren().add(取消按钮);
setId(konstanten.getPopupFooterCancelButtonId());
cancelButton.setValue(popup.getCancelText());
如果(!popup.getCancelAction().equals(“”){
字符串表达式=“#{”+popup.getCancelAction()+“}”;
MethodExpression MethodExpression=ExpressionHelper.EXPRESSION\u HELPER。
generateMethodExpression(表达式,null,
新类[]{ActionEvent.Class});
cancelButton.addActionListener(新方法ExpressionActionListener(
方法(表达式);
}否则{
cancelButton.setOnclick(“hidePopup(““+componentId+”)”);
}
cancelButton.encodeAll(上下文);
}
writer.endElement(HTML\u DIV\u标记);
按钮是可见的,但单击它时除了重新加载页面外,什么也不会发生

getCancelAction()返回“nameofBean.nameofMethod”

没有错误消息

谢谢你的帮助

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

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


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

我改变了方法,所以它使用了一个直接ActionListener,它应该只打印“action”,但这也不起作用。没人知道吗?
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);