Java JSF2.0 HTMLCommandButton不';t在自定义组件中调用ActionListener
我目前正在JBoss AS 7.1上开发一个带有普通JSF的弹出窗口,并试图在弹出窗口类的呈现器中添加一个命令按钮。类弹出窗口扩展了UIPanel。 弹出窗口位于一个h:窗体内 将按钮添加到弹出窗口的代码: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
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);