2012-06-19 63 views
0

是否有人懂得「翻譯/覆蓋」春季安全$ {} SPRING_SECURITY_LAST_EXCEPTION.message到 JSF 的FacesMessage,以顯示它在PrimeFaces 號碼:咆哮組件?

有可能做到這一點與JavaScript代碼?

下面是一些代碼:

<h:form id="loginForm" prependId="false"> 
    <p:panel id="panelLogin"> 

     <h:panelGrid columns="2"> 
      <h:outputLabel for="j_username" value="User" /> 
      <p:inputText id="j_username" required="true" label="Username" name="j_username" /> 

      <h:outputLabel for="j_password" value="Pwd" /> 
      <p:password id="j_password" required="true" label="Password" /> 

     </h:panelGrid> 

     <p:commandButton value="GO!" ajax="false" 
      onclick="document.loginForm.action='#{request.contextPath}/j_spring_security_check';document.loginForm.method='post';" /> 

    </p:panel> 
</h:form>   

<!-- This works: --> 
<c:if test="${not empty param.login_error}"> 
    <h:outputText value="${SPRING_SECURITY_LAST_EXCEPTION.message}" /> 
</c:if> 

<!-- Target component to show FacesMessages --> 
<p:growl id="loginGrowl" /> 

回答

0

我自己做這個:

<c:if test="${not empty param.login_error}"> 
    <p:growl> 
     <f:event type="preRenderComponent" listener="#{GrowlCtrl.preRender}" /> 
     <f:attribute name="error" value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/> 
    </p:growl> 
</c:if> 



public class GrowlCtrl implements Serializable { 

    public void preRender(ComponentSystemEvent cse) throws AbortProcessingException { 
     Map<String, Object> atributos = cse.getComponent().getAttributes(); 
     String error = (String)atributos.get("error"); 
     if (error != null && !"".equals(error)) { 
      FacesContext facesContext = FacesContext.getCurrentInstance(); 
      facesContext.addMessage("", new FacesMessage(error)); 
     } 
    } 

} 
相關問題