4 Replies Latest reply on Mar 17, 2007 7:46 AM by Alex

    Problem with h:message and a4j

    Alex Newbie

      Hi,
      I have got a curious problem with this login-subview:

      <f:subview id="leftSide">
       <rich:panel id="LoginPanel">
       <f:facet name="header">
       <h:outputText value="Login"/>
       </f:facet>
      
       <a4j:form id="loginForm" ajaxSubmit="true">
       <h:outputText value="Login:" />
       <h:inputText id="userLogin" value="#{authenticBean.login}" binding="#{authenticBean.loginInput}" required="true"/>
       <f:verbatim><br></f:verbatim>
       <h:outputText value="Pass:" />
       <h:inputSecret id="PW" value="#{authenticBean.password}" validator="#{authenticBean.validateLogin}" required="true"/>
       <f:verbatim><br></f:verbatim>
       <h:message for="PW" />
       <a4j:commandButton reRender="mainLogin" action="success" value="Login"/>
       <f:verbatim><br></f:verbatim>
       </a4j:form>
       </rich:panel>
      </f:subview>
      


      Everything works fine, but if I throw a validation exception and <h:message ...> should be used, the validation message will be written between <outputText "Pass"> and the secret inputfield.

      If I push the Login Button again the message appears between <outputText "Login"> and <inputText for "Login">.

      Perhaps it´s too late, but what I am doing wrong? :)

        • 1. Re: Problem with h:message and a4j
          Sergey Smirnov Master

          I wonder, why the message appears at all. It should not if it is Ajax. Probably, it is not.

          Replace <a4j:form id="loginForm" ajaxSubmit="true"> with just <h:form id="loginForm"/>

          Put <h:form> around the panel, not inside

          put <a4j:outputPanel ajaxRendered="true"> around the h:message. I.e.
          <a4j:outputPanel ajaxRendered="true">
          <h:message for="PW" />
          </a4j:outputPanel>

          Your a4j:commandButon has two attribute reRender and action. One of them is void

          If you have a navigation rule for "success", the whole page will be replaced (It is "Ajax request generates non-ajax response" mode). In this case reRender does not make any sense

          In case of the validation (or conversion) is failed, the "mainLogin" will be refreshed. However, I do not see this target in your code snippet. Do you want to re-render "mainLogin" in case of error (in case of no error, it will not be re-rendered)



          • 2. Re: Problem with h:message and a4j
            Alex Newbie

            Hi thnx for your help.

            I tried to use the a4j-include Demo and in this code the button has a reRenderer and action value:

            <f:facet name="footer">
             <h:panelGroup>
             <h:messages styleClass="error" />
             <a4j:commandButton action="next" value="Next >>" reRender="wizard"/>
             </h:panelGroup>
            </f:facet>
            
            


            I changed now my subview like you said and after i delete "reRender=mainLogin" everything works. My mainLogin is in the mainView (the loginform is a subview of it) and look like this:



            <f:view>
             <h:panelGroup styleClass="leftSide" id="mainLogin">
             <a4j:include rendered="#{!authenticBean.userlogged}" id="_leftSideLogin" viewId="/pages/includes/_leftSideLogin.jsp"/>
             <a4j:include rendered="#{authenticBean.userlogged}" id="_leftSideUserMenu" viewId="/pages/includes/_leftUserMenu.jsp"/>
             </h:panelGroup>
            
             <a4j:include id="mainInclude" viewId="/pages/includes/_home.jsp"/>
            </f:view>
            


            I tought that was similiar the same as the a4j-include demo.

            Alex

            • 3. Re: Problem with h:message and a4j
              Alex Newbie

              (I can't find a edit button)
              Edit: If I change the value-tag with the reRender-tag I got my old problem (wandering messages). I play around to a bit and putt the <h:form> outside the panel, but this had no effect.

              Here is my corrected code:

              <f:subview id="leftSide">
              
              
               <rich:panel id="LoginPanel">
               <f:facet name="header">
               <h:outputText value="Login"/>
               </f:facet>
              
               <h:form id="loginForm">
               <h:outputText value="Login:" />
               <h:inputText id="userLogin" value="#{authenticBean.login}" binding="#{authenticBean.loginInput}" required="true"/>
               <f:verbatim><br></f:verbatim>
               <h:outputText value="Pass:" />
               <h:inputSecret id="PW" value="#{authenticBean.password}" validator="#{authenticBean.validateLogin}" required="true"/>
               <f:verbatim><br></f:verbatim>
              
               <a4j:outputPanel ajaxRendered="true">
               <h:message for="PW" />
              
               </a4j:outputPanel>
              
               <a4j:commandButton reRender="mainLogin" value="Login"/>
               <f:verbatim><br></f:verbatim>
               </h:form>
               </rich:panel>
              </f:subview>
              


              • 4. Re: Problem with h:message and a4j
                Alex Newbie

                Ok, after I changed the <h:panelGroup> tags to <a4j:outputPanel> in the main.jsp my messages are working now :)
                I have to press my Login button three times before the first message appears but I think I will finding this error :)

                Cu