How to display my application's errors in JSF?

后端 未结 8 1496
栀梦
栀梦 2020-11-29 18:10

In my JSF/Facelets app, here\'s a simplified version of part of my form:


  

        
相关标签:
8条回答
  • 2020-11-29 18:48

    I tried this as a best guess, but no luck:

    It looks right to me. Have you tried setting a message severity explicitly? Also I believe the ID needs to be the same as that of a component (i.e., you'd need to use newPassword1 or newPassword2, if those are your IDs, and not newPassword as you had in the example).

    FacesContext.getCurrentInstance().addMessage("newPassword1", 
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error Message"));
    

    Then use <h:message for="newPassword1" /> to display the error message on the JSF page.

    0 讨论(0)
  • 2020-11-29 18:56

    JSF is a beast. I may be missing something, but I used to solve similar problems by saving the desired message to a property of the bean, and then displaying the property via an outputText:

    <h:outputText
        value="#{CreateNewPasswordBean.errorMessage}"
        render="#{CreateNewPasswordBean.errorMessage != null}" />
    
    0 讨论(0)
提交回复
热议问题