有人知道如何翻译/覆盖" 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" />
答案 0 :(得分: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));
}
}
}