3 Replies Latest reply on Oct 7, 2014 4:33 AM by michpetrov

    Any way to return server side error message to datascroller when page forward clicked?

    achildress

      I have a datascroller on a page that when clicked, calls a server side action method that does some database work. I have a need to send back an error message if something goes wrong with the database work and a server side exception occurs, thus causing a status 500 to be returned to the ajax call.

       

      Currently I'm doing this on the server side when the exception occurs:

       

      throw new Exception("something bad happened");

      catch (Exception e) {

         FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), e.getMessage()));

      }

       

      Implementing the onError method of XMLHttpRequest to display what is returned as follows does no good, as the message doesn't seem to be coming back in either the message variable, or in the responseText variable of req:

      A4J.AJAX.onError = function(req,status,message) {

           window.alert(req.getResponseText());

            window.alert(req.responseText);

           window.alert(message);

      }

       

      I've also tried droping a <a4j:log/> tag on the page just to see what is returning, but nothing is being displayed.

       

      We are using the 3.3.1 GA release of richfaces currently.

       

      How can I send feedback to the calling page when the datascroller is clicked and it results in a server side exception?

        • 1. Re: Any way to return server side error message to datascroller when page forward clicked?
          michpetrov

          The response contains pieces of HTML that are to be added/replaced on the page, since there is no component that would display the message it's not included. To show a FacesMessage use h:message or rich:message(s).

          • 2. Re: Any way to return server side error message to datascroller when page forward clicked?
            achildress

            Michal, I'm really interested in how to pass some sort of message/information back to the page via the ajax request object, so I can determine if the 500 ajax status was the result of an unexpected error, or an error I specifically sent back to the page for the purposes of informing the user of something. I realize that I can use rich:messages, but the A4J.AJAX.onError method I have defined at an application level is hijacking that process and forwarding to my error page, so the user never gets to see the rich:messages. I'm trying to put something in the ajax request object so that my A4J.AJAX.onError method can look for it and do something different instead of forwarding to my error page. Is there any way to do this?

            • 3. Re: Any way to return server side error message to datascroller when page forward clicked?
              michpetrov

              If you need to do different things based on the server response you can use a different status code, leave 500 for the server and send back 555 or something (status codes 512-599 are currently unassigned so you can use any one of those). Alternatively you can define navigation rules in faces-config.xml, so you can redirect to certain pages based on the result of a server-side function.

               

              If you really need to modify the response you can implement a phaseListener and put something into the response during Render Response Phase.