基于以下链接How to programmatically add an AjaxBehavior to a UIComponent with primefaces中提出的解决方案
我已经以编程方式实现了CommanLink。调用actionListener方法openDialogListener
,但来自primefaces对话框架的openDialog
不起作用。如果我将openDialogListener
方法设置为普通的jsf命令链接,一切都按预期工作,所以我认为问题出在writeLink
方法
这是我的代码:
private void writeLink(HtmlTag parent,String text) throws IOException{
String action = "#{myBean.openDiaog}";
CommandLink link = (CommandLink)FacesContext.getCurrentInstance().getApplication().createComponent(CommandLink.COMPONENT_TYPE);
link.setId(FacesContext.getCurrentInstance().getViewRoot().createUniqueId());
link.setValue(text);
ExpressionFactory ef = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
MethodExpression me = ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), action, null, new Class<?>[]{BehaviorEvent.class});
AjaxBehavior ajaxBehavior = (AjaxBehavior) FacesContext.getCurrentInstance().getApplication().createBehavior(AjaxBehavior.BEHAVIOR_ID);
ajaxBehavior.setProcess("@this");
//ajaxBehavior.setUpdate("@this");
ajaxBehavior.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(me, me));
link.addClientBehavior("click", ajaxBehavior);
this.addChild(link);
parent.getChildren().add(link);
}
这里是听众
public void openDialogListener(javax.faces.event.AjaxBehaviorEvent e){
Map<String, Object> options = new HashMap<String, Object>();
options.put("modal", true);
options.put("draggable", true);
options.put("resizable", true);
options.put("width", 600);
options.put("height", 500);
RequestContext.getCurrentInstance().openDialog("myDialog", options, null);
}
不幸的是,没有错误/没有异常