10 Replies Latest reply on Jun 25, 2009 7:06 AM by sam-user

    Setting actionparam  value

    sam-user

      Hello, I have to execute an action against a text field. My page contains the following:

      <s:decorate id="locField" template="layout/edit.xhtml">
       <ui:define name="label">Loc</ui:define>
       <h:inputText id="aLoc" value="#{alHome.instance.alLoc}">
       <a:support event="onblur" reRender="locField" bypassUpdates="true" ajaxSingle="true"/>
       </h:inputText>
      
       <a:commandButton value="Search" image="img/search.GIF" id="searchImg" action="#{locSearch.search}" >
       <a:actionparam name="aLoc" value="#{alHome.instance.alLoc}" assignTo="#{locSearch.searchString}"/>
       </a:commandButton>
      </s:decorate>


      The problem I have is that in my locSearch bean the value assigned to searchString is null. If I put a literal as a value of the action param

      <a:actionparam name="aLoc" value="1234" assignTo="#{locSearch.searchString}"/>


      the value of searchString is set properly.

      Could someone please tell me what am I doing wrong and how do I pass the value of the text field aLoc to my action bean.

      Thank you.

        • 1. Re: Setting actionparam  value
          sam-user

          Hello again,
          could anyone help me with this. I'm really stuck here - I searched in this forum and in the documentation but so far I was unable to figure out what I am doing wrong.
          Thanks

          • 2. Re: Setting actionparam  value
            ilya_shaikovsky

            add ajaxSingle true to the button.

            • 3. Re: Setting actionparam  value
              sam-user

              That changed the behavior, but not as I expected it. I can now get the value of the "previous" request.
              So if I typed "value1" in the the text field and click the button , in my action bean I get null. The second time I click the button I get "value1" in my bean.
              That can't be right, can it?
              Actually I just gave it another go without the ajaxSingle attribute and it does exactly the same thing - the bean gets the previous value of the field - something I didn't notice before.

              • 4. Re: Setting actionparam  value
                sam-user

                Ignore the last statement of my previous post - it's not true.
                But I still cannot pass the value of the input text field via actionparam to the action bean with the first click on the button. It onlly works the second time.
                Any thoughts what might be the reason?
                Thank you.

                • 5. Re: Setting actionparam  value
                  ilya_shaikovsky

                  I see two problems with initial code:

                  1) parameter encoded during button encode. And initially it is null. So button passes this null after clicked current parameter. it's not evaluated after button click but just passed. So you can't use it like you defined. Just get the submitted #{alHome.instance.alLoc} in your action.

                  2) support on onblur and button will cause two concurrent request fired if the input focused and button clicked. And this not seems good approach.

                  • 6. Re: Setting actionparam  value
                    sam-user

                    Thanks Ilya,
                    It's clearer now, but still some gray areas (obviously still trying to find my way around).

                    1) parameter encoded during button encode. And initially it is null. So button passes this null after clicked current parameter. it's not evaluated after button click but just passed. So you can't use it like you defined


                    That explains the missing value the first time the button is clicked, but what do you mean by:

                    Just get the submitted #{alHome.instance.alLoc} in your action.

                    Not quite sure how to do that.

                    Also

                    support on onblur and button will cause two concurrent request fired if the input focused and button clicked. And this not seems good approach.


                    Isn't there order in which these are executed?

                    Thank you.

                    • 7. Re: Setting actionparam  value
                      ilya_shaikovsky

                      "Just get the submitted #{alHome.instance.alLoc} in your action."

                      after you clicking button the #{alHome.instance.alLoc} model objects gets updated with new value. Just use this value.

                      "Isn't there order in which these are executed?"

                      using queue (described in documentation) will allow to send them one by one.

                      • 8. Re: Setting actionparam  value
                        sam-user

                        Thanks Ilya,

                        after you clicking button the #{alHome.instance.alLoc} model objects gets updated with new value. Just use this value.


                        This worked, but only after I removed the

                        bypassUpdates="true"


                        from the onblur support.

                        Just one more question, though - if I have this

                        <s:decorate id="locField" template="layout/edit.xhtml">
                         <ui:define name="label">Loc</ui:define>
                         <h:inputText id="aLoc" value="#{alHome.instance.alLoc}">
                         <a:support event="onblur" reRender="locField" ajaxSingle="true" eventsQueue="locLookup"/>
                         </h:inputText>
                        
                         <a:commandButton value="Search" image="img/search.GIF" id="searchImg" action="#{locSearch.search}" eventsQueue="locLookup">
                         <a:actionparam name="aLoc" value="#{alHome.instance.alLoc}" assignTo="#{locSearch.searchString}"/>
                         </a:commandButton>
                        </s:decorate>


                        Wouldn't it be correct to assume that once a text is typed in the text field(aLoc) and the onblur event occurs and re-renders the locField tree, then the actionparam value is updated with the entered text and the actual value of alHome.instance.alLoc is passed to the bean via actionparam?

                        Thanks.

                        • 9. Re: Setting actionparam  value
                          ilya_shaikovsky

                           

                          Thanks Ilya,
                          Quote:
                          after you clicking button the #{alHome.instance.alLoc} model objects gets updated with new value. Just use this value.



                          This worked, but only after I removed the
                          Code:
                          bypassUpdates="true"

                          talking about support yes. But the button had no bypass and ajax single flags from the beggining in your code. So it should update the model correctly after clicked.

                          And your assumption about last code seems correct. But it still not clear for me why you need this param at all. you could get just the #{alHome.instance.alLoc} submitted value from #{locSearch.search}.

                          • 10. Re: Setting actionparam  value
                            sam-user

                             

                            But it still not clear for me why you need this param at all. you could get just the #{alHome.instance.alLoc} submitted value from #{locSearch.search}.


                            I guess you mean in #{locSearch.search} instead of from.
                            Mainly, because I'm still learning and I hadn't thought about getting the value I need directly from the Home instance. Old habits die hard :-)
                            Thanks a lot for your help.