2015-03-03 39 views
0

在使用ConfirmBehavior對按鈕進行Ajax更新後,所有確認對話框屬性(標題,消息,圖標)變爲空值。ConfirmBehavior不支持Ajax回溯

其看起來像放入系統值在buildView階段只(applyMetadata功能)

在ConfirmBehavior的getHeader()/getMessage()/getIcon()方法沒有表達的評價進行評價。

如何在這一點上得到真實的表達? (以呈現階段對其進行評估)

回答

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"); 
     } 

    } 
... 
}