8 Replies Latest reply on Jan 10, 2012 12:00 AM by Jason Porter

    How to display the custome FacesMessage...

    hantsy bai Master

      I wanted to displayed some FacesMessage in current view due to some business logic validation failure.


      In the before Seam2 application, there is a FacesMessages, when I add an error, it will prevent page redirect and stay on current page. But in JBoss Seam3, I can not use an effective way to postback and display the messages.



      1. I try to threw a Jsf VlidatorException in the code, and I got EJBTransacationException, the whole conversation was stopped.
      I hope the jsf handle this exception, and display the message, but obviously it dose not.


      SEAMFACES-226


      2. I tried to use Messages(form Seam international), use messages.error to add a messages, but it does not prevent page redirect, and redirect to the target page defined.


      SEAMFACES-225


      3. I tried to use FacesContext to add an error, facesContext.add(null, new FacesMessage(,,,)), and defined the navigation rule, and use a boolean flag in the Bean class, it can redirect to the current page. But it return to current page by redirect, not post back action, all the values in the form will be disappeared.


      I am using JBoss Seam 3.1.0CR1, JBoss 7.0.1.Final(jsf 2.0.2, due to an Ajax problem, I downgraded the JSF to 2.0.2).


      Any help here? Thanks


        • 1. Re: How to display the custome FacesMessage...
          Bernard Labno Master

          hantsy,
          In Seam2 you could not stop navigation with facesMessages. There was never such option.
          Use navigation rules. They are meant for such cases.

          • 2. Re: How to display the custome FacesMessage...
            hantsy bai Master

            I promise the Seam 2 FacesMessages can prevent navigation...


            public void sendMessage() {
                      if (messageBox.getToAddress() == null
                                || messageBox.getToAddress().trim().length() == 0) {
                           facesMessages.add(Severity.ERROR, "to address is required.");
                           return;
                      }
                      try {
                           messageBox.send();
                      } catch (Exception ex) {
                           return;
                      }
                      facesMessages.add(Severity.INFO, "Message is sent!");
                      Events.instance().raiseEvent(
                                MessagingConstants.EVENT_LOAD_CONTENT_TEMPLATE,
                                MessagingNavigationEnum.MESSAGE_BOX,
                                MessagingNavigationEnum.MESSAGE_PAGE);
                 }
            
            



            This is the real code fragment from my before application(Seam 2.2). I used it frequently in the before application.



            Using navigation rule will abandon the content in form...I have comments in the issues.


            Any good idea for this problem? 

            • 3. Re: How to display the custome FacesMessage...
              Jason Porter Master

              Ignoring the fact that this method doesn't even compile... You're calling a void method, from I assume, an action method which will tell JSF to return to the same page. If you're thinking the Messaging* enums / Strings you have at the end do anything, there is no class in Seam with those names.

              • 4. Re: How to display the custome FacesMessage...
                hantsy bai Master

                MessagingNavigationEnum is my custom class, not provided by Seam 2.

                • 5. Re: How to display the custome FacesMessage...
                  hantsy bai Master

                  OK, ignore the FacesMessages now, I am using Seam 3.1.0Final now.


                  Using navigation rule will abandon the content in form...I have comments in the issues. 
                  



                  How to display a custom message effective in Seam3?

                  • 6. Re: How to display the custome FacesMessage...
                    Jason Porter Master

                    I must not be understanding something because it hasn't changed. You can still use FacesContext.addMessage(...) unless you have some redirect happening (but I think we should be supporting that).

                    • 7. Re: How to display the custome FacesMessage...
                      hantsy bai Master

                      Maybe I changed the programming style...in the Seam2 application, I used Ajax and event frequently...


                      In Seam 3, I avoided Ajax sometime, especially the partial page render(many problems I encountered, I have complained many times in this forum ).


                      Thanks.

                      • 8. Re: How to display the custome FacesMessage...
                        Jason Porter Master

                        hantsy bai wrote on Jan 09, 2012 23:28:


                        Maybe I changed the programming style...in the Seam2 application, I used Ajax and event frequently...

                        In Seam 3, I avoided Ajax sometime, especially the partial page render(many problems I encountered, I have complained many times in this forum ).

                        Thanks.


                        Yeah, JSF issues :( unfortunately we can't control AJAX in JSF or fix their bugs.