0

有人知道如何将 Spring Security ${SPRING_SECURITY_LAST_EXCEPTION.message} “翻译/覆盖”成JSF FacesMessage,以便在 PrimeFaces p:growl组件中显示它吗?

可以用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" />
4

1 回答 1

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

}
于 2012-06-20T10:29:04.223 回答