7 Replies Latest reply on Dec 3, 2010 7:22 AM by heapifyman heapifyman

    a4j:actionparam and h:commandButton

    heapifyman heapifyman Newbie

      Hello everyone,

       

      I'm trying to use the a4j:actionparam with a h:commanButton.

      According to:

      http://livedemo.exadel.com/richfaces-demo/richfaces/actionparam.jsf

       

      it should work "with non-ajax command component also" but in my case it doesn't.

       

      Basically, what I tried to do is combine the two examples on above mentioned page:

      The "Change Demo Appplication Skin To:" example and the "Show Screen Size" example by using

       

                 <h:commandButton id="submit" value="Login" action="#{identity.login}">
                      <a:actionparam name="w" value="screen.width"
                           assignTo="#{environmentBean.screenWidth}" noEscape="true" />
                      <a:actionparam name="h" value="screen.height"
                           assignTo="#{environmentBean.screenHeight}" noEscape="true" />
                 </h:commandButton>
      <h:commandButton id="submit" value="Login" action="#{identity.login}">
           <a:actionparam name="w" value="screen.width" 
                assignTo="#{environmentBean.screenWidth}" noEscape="true" />
           <a:actionparam name="h" value="screen.height" 
                assignTo="#{environmentBean.screenHeight}" noEscape="true" />
      </h:commandButton>
      

       

      But the bean properties are not set when clicking the commandButton.

       

      Am I missing something?

      Thanks,

      Philip

        • 1. Re: a4j:actionparam and h:commandButton
          navy zhang Newbie

          you may user <f:setPropertyActionListener value="screen.width"
                                      target="bean.param" />

          it can set by self

           

          i think you are right do that

          you may try a4j:commandButton

          • 2. Re: a4j:actionparam and h:commandButton
            heapifyman heapifyman Newbie

            Unfortunately,

            <f:setPropertyActionListener value="screen.width" target="bean.param" />

            will then introduce "screen.width" literally into the bean param, when indeed it should be the result of the javascript field screen.width

             

            How would I do that?

            • 3. Re: a4j:actionparam and h:commandButton
              Ilya Shaikovsky Master

              It will not works with h:command* component. Action param not encodes itself - component performs that. So a4j:command* knows about escape=false and cared about that so output looks like: w:screen.width(where screen width interpreted as js statement). And h:command* will always encode it like w:'screen.size' so it will be sent to server as string instead of calculated size.

               

              f:setProperty works with server side object and not encoded as param to the client at all so it will not works either.

               

              As solution you could use a4j:command* if possible or extend h:command to take care about escappe attribute of the parameter.

              1 of 1 people found this helpful
              • 4. Re: a4j:actionparam and h:commandButton
                heapifyman heapifyman Newbie

                Thanks for the explanation.

                 

                a4j:command* does not seem to fit here as submitting the form (a login actually) should redirect to another page.

                Also I have problems displaying the facesmessages for failed login attempts then. At least they are not displayed when using a a4j:command* instead of h:command*

                 

                But I think I found a different solution now using seam's webremoting stuff. It might not be the most elegant solution but it's working for now...

                • 5. Re: a4j:actionparam and h:commandButton
                  Ilya Shaikovsky Master

                  1) a4j:command* supports navigation if it's defined as redirect actually.

                  2) messages should be displayed if rich:messages and not h:* used

                  • 6. Re: a4j:actionparam and h:commandButton
                    heapifyman heapifyman Newbie

                    Thanks for the hint. I will try that.

                    • 7. Re: a4j:actionparam and h:commandButton
                      heapifyman heapifyman Newbie
                      <h:messages id="messages" globalOnly="true"
                      styleClass="message" errorClass="errormsg" infoClass="infomsg"
                      warnClass="warnmsg" rendered="#{showGlobalMessages != 'false'}" />

                      So <rich:messages> kinda works, but I have another stupid question:

                      I replaced the existing

                       

                           <h:messages id="messages" globalOnly="true"
                                styleClass="message" errorClass="errormsg" infoClass="infomsg"
                                warnClass="warnmsg" rendered="#{showGlobalMessages != 'false'}" />
                      

                       

                       

                      with

                       

                       

                           <rich:messages id="messages" globalOnly="true" 
                                styleClass="message" errorClass="errormsg" infoClass="infomsg" 
                                warnClass="warnmsg" rendered="#{showGlobalMessages != 'false'}" />
                      

                       

                       

                      But now the little error/warning/info signs are not displayed anmore. Just the error message.

                       

                      Any idea why?