开发者

Rerender RichFaces error message after ajax request

开发者 https://www.devze.com 2023-01-08 02:29 出处:网络
I am using custom ajax-called javacode that does some processing on the server. In this process various errors can occure that I add to the FacesContext via ad开发者_开发问答dMessage().

I am using custom ajax-called javacode that does some processing on the server. In this process various errors can occure that I add to the FacesContext via ad开发者_开发问答dMessage(). I want to display these messages in the same <rich:messages>-tag that I use for my validation errors.

Do you know a way to display these messages in the <rich:messages>-tag after the ajax-request completed?

My initial idea was adding <a4j:jsFunction name="richDisplayError" reRender="messages" /> to the markup and calling richDisplayError when the request completed, but it seems the messages panel is rerendered empty.


<rich:messages> has ajaxRenderedset to true by default. So the problem lies elsewhere. Perhaps:

  • you are redirecting, instead of forwarding, and the messages are lost
  • you aren't actually adding the messages (check with debug)
  • you are having different/lacking views/subviews


For example, in your page:

    <a4j:commandButton value="Action"
           limitToList="true" 
           action="#{mybean.action}"
           reRender="mymessages">
    </a4j:commandButton>
    <a4j:outputPanel ajaxRendered="true">
       <h:messages id="mymessages"  />
    </a4j:outputPanel>

then in you bean:

public void action(){                         
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("hello world")); 
}    


You need 3 things :

1st : declare your error message, in the "\resources\bundle\errorMessages.properties" file, like this :

errorMsgToDisplay.errName = Your Error Message Here

2nd : declare your BUNDLE variable in the class code :

private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("/bundle/errorMessages");

3rd : Display the message (after an condition for example )

if  ( condition ) {
FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_ERROR, 
BUNDLE.getString("errorMsgToDisplay.errName"),
BUNDLE.getString("errorMsgToDisplay.errName")));
}
0

精彩评论

暂无评论...
验证码 换一张
取 消