7 Replies Latest reply on Dec 16, 2009 4:57 PM by idyoshin

    Assign value to a bean property from pages.xml

      I want to assign a value to a string contained in a backing bean using pages.xml.


      I tried with



      <param name="Trial" value="#{personHome.trialstring}">





      but when i try to see the value of


      #{personHome.trialstring}



      in my home.xhtml i find that such value is null.

        • 1. Re: Assign value to a bean property from pages.xml
          josdaniel

          are you setting an appropriate value for Trial from where it is re-directed to the new page?

          • 2. Re: Assign value to a bean property from pages.xml

            Maybe I don't understand what do you mean as appropriate.
            I need to save in my bean a string that I'll use then to redirect my navigation. So I was thinking to assign a different label in the way I described here.
            In personHome i defined a private String trialstring with getter and setter, and I was thinking to assign with param a value to such string.
            Am I completely wrong with this?


            F.


            (I was inspired by Seam Framework Experience by Yuan et al. ch. 15)

            • 3. Re: Assign value to a bean property from pages.xml
              mikkus70

              The <param> tag serves to map request parameters to backing beans, not to assign them values directly. When a link is being rendered, it works backwards (i.e., it maps the value of the backing bean into the request parameter).


              So, in your example, if you make a request http://localhost/....xhtml?Trial=test, you'll see that #{personHome.trialstring} = "test", but if you don't pass a value in the request, it will be null (unless #{personHome.trialstring} also exists in the view in which the link is being rendered and has a value). This is what Joshua intended.


              To add a parameter to the request if there are no instances of personHome in the view in which you're rendering your link to this page, you can use:


              <s:link view=" ... ">
                  <f:param name="Trial" value=" ... " />
              </s:link>
              


              • 4. Re: Assign value to a bean property from pages.xml

                Great! This helped me a lot!
                But I still have an issue. Let's suppose that i want to use the s:button. This tag doesn't submit the form. So I tried using h:commandButton together with f:param, but that did not work. So the questions are:
                1) how can I use the s:button and at the same time submit my form?
                2) why s:button (or s:link) and f:param work and h:commandbutton doesn't?


                Thank you very much!

                • 5. Re: Assign value to a bean property from pages.xml

                  I tried to fix everything by using the s:button with the attribute :



                  onclick="submit();"





                  But whenever I click on the button I get a concurrent call to conversation error. Any idea?

                  • 6. Re: Assign value to a bean property from pages.xml
                    idyoshin

                    Hello,


                    you shouldn't call javascript methods in the JSF, unless you know what you're doing. I guess it will brake the JSF lifecycle. In your situation there is a call to JSF submit-format, when you click the button,and second another one call is submitted.


                    If you need to submit the form values to your bean without calling specific methods - simply create <h:commandButton value="Your caption"/> in that form - that would be enough. And if you need to make some callbacks when its ready - then you can add <a4j:support event="oncomplete" action="#{bean.action()}" />... but in general that would be the same as <h:commandButton value="Your caption" action="#{bean.action()}"/> .


                    you should always think about JSF lifecycle.


                    Read something like following:
                    http://www.roseindia.net/jsf/jsflifecycle.shtml



                    Regards!


                    Ilya Dyoshin

                    • 7. Re: Assign value to a bean property from pages.xml
                      idyoshin

                      Hello again.


                      and if you need simply pass additional value that is not in the form you can use facelets setPropertyActionListener tag


                      regards,


                      Ilya Dyoshin