views:

178

answers:

2

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 addMessage(). 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.

+1  A: 

<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
Bozho
I think ajaxRendered is useless in this case, since I am making the ajax call via the a4j framework, but with custom functions. Is that the reason, how long do the messages live? are they lost when i fire another call?
Tobo
`<a4j:jsFunction` is still the a4j frameweork.
Bozho
A: 

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