相关疑难解决方法(0)

如何在JSF中显示我的应用程序错误?

在我的JSF/Facelets应用程序中,这是我表单的一部分的简化版本:

<h:form id="myform">
  <h:inputSecret value="#{createNewPassword.newPassword1}" id="newPassword1" />
  <h:message class="error" for="newPassword1" />
  <h:inputSecret value="#{createNewPassword.newPassword2}" id="newPassword2" />
  <h:message class="error" for="newPassword2" />
  <h:commandButton value="Continue" action="#{createNewPassword.continueButton}" />
</h:form>
Run Code Online (Sandbox Code Playgroud)

我希望能够根据continueButton()方法中发生的事情为特定的h:message标记分配错误.需要为newPassword和newPassword2显示不同的错误.验证器不会真正起作用,因为将传递结果的方法(来自DB)在continueButton()方法中运行,并且运行两次太昂贵.

我无法使用h:messages标记,因为该页面有多个地方需要显示不同的错误消息.当我尝试这个时,页面显示每条消息的重复.

我试过这个是最好的猜测,但没有运气:

public Navigation continueButton() {
  ...
  expensiveMethod();
  if(...) {
    FacesContext.getCurrentInstance().addMessage("newPassword", new FacesMessage("Error: Your password is NOT strong enough."));
  }
}
Run Code Online (Sandbox Code Playgroud)

我错过了什么?任何帮助,将不胜感激!

error-handling jsf facelets

40
推荐指数
3
解决办法
15万
查看次数

JSF身份验证:无法拦截错误消息

我已经开发了一个简单的登录表单,可以在我的JSF + PrimeFaces页面中使用:

<form action="j_security_check" method="post"> 
    <p:dialog modal="true" header="Login" widgetVar="loginDlg">
        <h:panelGrid columns="3" cellpadding="5">  
            <h:outputLabel for="j_username">Username:</h:outputLabel> 
            <h:inputText id="j_username" required="true" /> 
            <h:message for="j_username" /> 
            <h:outputLabel for="j_password">Password:</h:outputLabel> 
            <h:inputSecret id="j_password" required="true" /> 
            <h:message for="j_password" /> 
            <br /> 
            <h:commandButton value="Login" /> 
        </h:panelGrid>
    </p:dialog>                
</form> 
Run Code Online (Sandbox Code Playgroud)

尝试使用空密码,但缺少的密码(必需)不会被h:message组件捕获.我也转而p:commandButton认为问题可能出在按钮的Ajax行为中,但页面没有呈现,因为PrimeFaces抱怨CommandButton不在表单元素中.容器抛出的异常是:

com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Access denied on empty password for user pippo
Run Code Online (Sandbox Code Playgroud)

总结一下,我有两个问题:

  1. 为什么丢失的密码在提交表单之前不会产生消息?
  2. 如何捕获LoginException并在对话框中显示错误消息?

jsf login j-security-check primefaces

2
推荐指数
1
解决办法
3407
查看次数