![](/img/trans.png)
[英]JSF 2: Create a custom component with CommandButton and get attribute to ActionListener
[英]JSF 2.0 HTMLCommandButton doesn't call ActionListener in Custom Component
目前,我正在JBoss AS 7.1上使用纯JSF开发PopUp,并且试图在popup-class的渲染器中添加命令按钮。 Popup类扩展了UIPanel。 弹出窗口位于ah: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来查看表单是否有问题。 该链接看起来像在工作,但仍然没有任何调用。
问题是,这些按钮没有正确地添加到JSF组件树中。 我已将它们作为子项添加到组件中,并在encodeChildren()方法中忽略了它们。
如果有人知道更好的解决方案,我很想知道,所以请随时回答这个问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.