1 2 3 Previous Next 30 Replies Latest reply on Aug 1, 2007 5:26 PM by sergeysmirnov

    <a4j:commandButton> and <h:messages/>

    krasig

      This is my simple source test:

      <a4j:outputPanel id="myMessageanel" ajaxRendered="true">
       <h:messages />
      </a4j:outputPanel>
      
      <a4j:region id="a123">
      <h:form>
       <h:inputText value="#{delme.id}"></h:inputText>
       <a4j:commandButton action="#{delme.searchByID}" value="221" reRender="a123"></a4j:commandButton>
      </h:form>
      </a4j:region>


      BEan

      public String getId() {
       if (!id.equals("")) {
       try {
       throw new ObjectNotFoundException();
       } catch (ObjectNotFoundException e) {
       FacesContext.getCurrentInstance().addMessage(null,
       new FacesMessage(FacesMessage.SEVERITY_INFO,
       "No Result",
       ""));
       }
      
       }
       return id;
       }
       public void setId(String id) {
      
       this.id = id;
       }
       public String searchByID() {
       return null;
      
       }



      So TELL ME WHY MESSAGES NEVER SHOWN????
      WHAT IS WRONG??????

        • 1. Re: <a4j:commandButton> and <h:messages/>

          Do you thing that the getter is called?

          • 2. Re: <a4j:commandButton> and <h:messages/>
            krasig

            YES.
            I mean that after type in <h:inputText> some value and after press <a4j:commandbutton>
            (in getId() i have:

            if (!id.equals("")) {
             try {
             throw new ObjectNotFoundException();
             } catch (ObjectNotFoundException e) {
             FacesContext.getCurrentInstance().addMessage(null,
             new FacesMessage(FacesMessage.SEVERITY_INFO,
             "No Result",
             ""));
            e.printstacktrace();
             }
            
             }


            I see in SystemOut exception

            But in <h:message NONONONONO





            • 3. Re: <a4j:commandButton> and <h:messages/>
              krasig

              I tested some like this:

              public String getId() {
              
              FacesContext.getCurrentInstance().addMessage(null,
               new FacesMessage(FacesMessage.SEVERITY_INFO,
               "Test",
               ""));
               if (!id.equals("")) {
               try {
               throw new ObjectNotFoundException();
               } catch (ObjectNotFoundException e) {
               FacesContext.getCurrentInstance().addMessage(null,
               new FacesMessage(FacesMessage.SEVERITY_INFO,
               "No Result",
               ""));
              e.printstacktrace();
               }
              
               }
               return id;
               }
               public void setId(String id) {
              
               this.id = id;
               }
               public String searchByID() {
               return null;
              
               }
              



              The RED message always shown, but BLUE NEVER.
              Tel me WHY?

              Of course this is after type some value in ID and press BUTTON


              • 4. Re: <a4j:commandButton> and <h:messages/>

                May be the id is null, but not "" ?

                • 5. Re: <a4j:commandButton> and <h:messages/>
                  krasig

                  No.
                  Id is declared with:
                  String id="";

                  • 6. Re: <a4j:commandButton> and <h:messages/>

                     

                    "krasig" wrote:
                    No.
                    Id is declared with:
                    String id="";


                    Frankly speaking, I must to say that having such code is not correct in the property getter as soon as the getter is called several times during the JSF lifecycle. I guess, it does not called exactly at the moment you expect. You can check it if you put a phase tracker to your application.

                    Just for testing purpose, surround a4j:commandButton with a4j:region.

                    • 7. Re: <a4j:commandButton> and <h:messages/>
                      krasig

                      as you can see I have REGION

                      <a4j:region id="a123">
                      <h:form>
                       <h:inputText value="#{delme.id}"></h:inputText>
                       <a4j:commandButton action="#{delme.searchByID}" value="221" reRender="a123"></a4j:commandButton>
                      </h:form>
                      </a4j:region>


                      but this not helps.

                      P.S. if change <a4j:commandbutton> with <h:commandbutton> ---- NO PROBLEM



                      • 8. Re: <a4j:commandButton> and <h:messages/>

                         

                        "krasig" wrote:
                        as you can see I have REGION


                        This is a point, because you have it in a wrong place.
                        "Surround the a4j:commandButton" does not mean surround both h:inputText and a4j:commandButton. The difference is tremendous.

                        • 9. Re: <a4j:commandButton> and <h:messages/>
                          krasig

                          Ok. I don't know difference but after:

                          <h:form>
                           <h:inputText value="#{delme.id}"></h:inputText>
                          <a4j:region id="a123">
                           <a4j:commandButton action="#{delme.searchByID}" value="221" reRender="a123"></a4j:commandButton>
                          </a4j:region>
                          </h:form>


                          Result is the same.

                          P.S. I can paste more debug information if you think that will help

                          • 10. Re: <a4j:commandButton> and <h:messages/>

                            put the phase tracker into WEB-INF/lib and say on which phases the red code is invoked.
                            You can take the tracker from here (http://www.jsftutorials.net/faces-config/phaseTracker.html) if you do not have one yet.

                            • 11. Re: <a4j:commandButton> and <h:messages/>
                              krasig

                              Ok. I will.
                              But it's amazing for me why in one method , "RED" message is shown - "BLUE" not.

                              • 12. Re: <a4j:commandButton> and <h:messages/>
                                krasig

                                Ok. After putting phase tracker into WEB-INF/lib

                                The Code:

                                public String getId() {
                                 FacesContext.getCurrentInstance().addMessage(null,
                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                 "??????? ? ????????? ?????????1111.",
                                 ""));
                                
                                
                                 LOGGER.debug("GET 1 ------"+id);
                                 if (!id.equals("")) {
                                 LOGGER.debug("GET 2 ------"+id);
                                 FacesContext.getCurrentInstance().addMessage(null,
                                 new FacesMessage(FacesMessage.SEVERITY_INFO,
                                 "???? ??????? ????????2222.",
                                 "11"));
                                
                                 try {
                                 LOGGER.debug("GET 3 ------"+id);
                                 throw new ObjectNotFoundException();
                                
                                 } catch (ObjectNotFoundException e) {
                                 LOGGER.debug("GET 4 ------"+id);
                                 FacesContext.getCurrentInstance().addMessage(null,
                                 new FacesMessage(FacesMessage.SEVERITY_INFO,
                                 "???? ??????? ????????.",
                                 "11"));
                                 }
                                
                                 }
                                
                                
                                 return id;
                                 }


                                Trace is:
                                007-8-1 0:57:18 org.exadel.jsf.PhaseTracker beforePhase
                                INFO: BEFORE RESTORE_VIEW 1
                                2007-8-1 0:57:18 org.exadel.jsf.PhaseTracker afterPhase
                                INFO: AFTER RESTORE_VIEW 1
                                2007-8-1 0:57:18 org.exadel.jsf.PhaseTracker beforePhase
                                INFO: BEFORE APPLY_REQUEST_VALUES 2
                                2007-8-1 0:57:18 org.exadel.jsf.PhaseTracker afterPhase
                                INFO: AFTER APPLY_REQUEST_VALUES 2
                                2007-8-1 0:57:18 org.exadel.jsf.PhaseTracker beforePhase
                                INFO: BEFORE PROCESS_VALIDATIONS 3
                                DEBUG - GET 1 ------ (Delme.java:getId:35)
                                2007-8-1 0:57:18 org.exadel.jsf.PhaseTracker afterPhase
                                INFO: AFTER PROCESS_VALIDATIONS 3
                                2007-8-1 0:57:18 org.exadel.jsf.PhaseTracker beforePhase
                                INFO: BEFORE UPDATE_MODEL_VALUES 4
                                DEBUG - SET 1-1 (Delme.java:setId:61)
                                2007-8-1 0:57:18 org.exadel.jsf.PhaseTracker afterPhase
                                INFO: AFTER UPDATE_MODEL_VALUES 4
                                2007-8-1 0:57:18 org.exadel.jsf.PhaseTracker beforePhase
                                INFO: BEFORE INVOKE_APPLICATION 5
                                searchByID
                                2007-8-1 0:57:18 org.exadel.jsf.PhaseTracker afterPhase
                                INFO: AFTER INVOKE_APPLICATION 5
                                2007-8-1 0:57:18 org.exadel.jsf.PhaseTracker beforePhase
                                INFO: BEFORE RENDER_RESPONSE 6
                                DEBUG - GET 1 ------1 (Delme.java:getId:35)
                                DEBUG - GET 2 ------1 (Delme.java:getId:37)
                                DEBUG - GET 3 ------1 (Delme.java:getId:44)
                                DEBUG - GET 4 ------1 (Delme.java:getId:48)
                                2007-8-1 0:57:18 org.exadel.jsf.PhaseTracker afterPhase
                                INFO: AFTER RENDER_RESPONSE 6
                                


                                "RED" message is on display
                                "BLUE" - NO

                                • 13. Re: <a4j:commandButton> and <h:messages/>

                                  What if you set SEVERITY_ERROR for green and blue ?

                                  • 14. Re: <a4j:commandButton> and <h:messages/>
                                    krasig

                                    Nothing

                                    1 2 3 Previous Next