对具有ConfirmBehavior
的按钮进行Ajax更新后,所有确认对话框属性(标题,消息,图标)都变为空。
看起来只在buildView阶段(applyMetadata function)
评估thoses值在ConfirmBehavior的getHeader()
/ getMessage()
/ getIcon()
方法中,没有对表达式的评估。
如何在这一点上获得真正的表达? (在渲染阶段评估它)
答案 0 :(得分:0)
不是一个完美的解决方案
public class ConfirmBehavior extends ClientBehaviorBase {
private String header;
private String message;
private String icon;
@Override
public String getScript(ClientBehaviorContext behaviorContext) {
FacesContext context = behaviorContext.getFacesContext();
UIComponent component = behaviorContext.getComponent();
String source = component.getClientId(context);
if(component instanceof Confirmable) {
String headerExpr = (String) component.getAttributes().get("confirm_header");
if (headerExpr!=null)
this.header = (String) ContextUtil.eval(context, headerExpr);
String messageExpr = (String) component.getAttributes().get("confirm_message");
if (messageExpr!=null)
this.message = (String) ContextUtil.eval(context, messageExpr);
String iconExpr = (String) component.getAttributes().get("confirm_icon");
if (iconExpr!=null)
this.icon = (String) ContextUtil.eval(context, iconExpr);
String script = "PrimeFaces.confirm({source:'" + source + "',header:'" + getHeader() + "',message:'" + getMessage() + "',icon:'" + getIcon() + "'});return false;";
((Confirmable) component).setConfirmationScript(script);
return null;
}
else {
throw new FacesException("Component " + source + " is not a Confirmable. ConfirmBehavior can only be attached to components that implement org.primefaces.component.api.Confirmable interface");
}
}
...
}