6 Replies Latest reply on Jul 24, 2011 4:29 AM by sukharevd

    RF4. Obtaining URL parameters

    sukharevd

      Let's say I have a page which should contain different data-grid in accordance with the parameter of URL (e.g. /activities.xhtml?type=today). Each item of the list should have the link to somewhere, and this 'somewhere' should know the value of that URL parameter.

       

      There is a controller to decide which list to show. This controller is stored in request scope [and I think it should be so]. As far as I understand there is no way to transmit url parameter through the link inside data-grid item while transfered data is stored in request scope. So I made special bean in session scope to store url parameter.

       

      Unfortunately I could not make it works properly. The bean in session scope often stores old value of url-value instead of new one.

      If you're lucky and my computer is up you can see it here

      http://dsps.in:8080/richparams/activities.xhtml

      Just navigate using menu. 'Type' parameter will not be always synchronised with the content of page.

       

      My question is why does it work in such a weird way and how to make it works properly?

       

      I attaches sources of sample project which does nothing but show this problem.

        • 1. Re: RF4. Obtaining URL parameters
          bleathem

          You can use the <f:viewParam> introduced with JSF 2.0 to map request parameters to backing bean.

           

          If you are stuck on JSF 1.x, have a look at prettyfaces (http://ocpsoft.com/prettyfaces/) to achieve the same effect.

           

          Lastly, you can always lok at the facesContext.getExternalContext().getRequestParameterMap(), and parse the request parameters in your backing bean yourself.

          • 2. Re: RF4. Obtaining URL parameters
            sukharevd

            I DO use JSF2 and f:viewParam descriptor.

            It looks like they don't work in the way they should.

            • 3. Re: RF4. Obtaining URL parameters
              iabughosh

              hi Sukharev,

              I saw this code in your attachment :

              <rich:panelMenuItem>

                                                      <h:outputLink value="activities.xhtml?type=today">

                                                                <h:outputText value="Today Activities"></h:outputText>

                                                      </h:outputLink>

                                                      <f:param name="current" value="Today Activities" />

                                            </rich:panelMenuItem>

               

              try replacing it with this:

               

              <rich:panelMenuItem>

              <h:link outcome="activities.xhtml" includeViewParams="true" value="Today Activities">

                 <f:param name="type" value="today" />

              </h:link>

              <f:param name="current" value="Today Activities" />

              </rich:panelMenuItem>

               

              regards.

              • 4. Re: RF4. Obtaining URL parameters
                sukharevd

                Amazing!

                 

                But why is it so?

                • 5. Re: RF4. Obtaining URL parameters
                  iabughosh

                  with JSF 2 , h:link is designed to submit GET requests and pass URL parameters using f:param or outcome="yourpage.xhtml?param=value", unlike the other commands which uses POST requests.

                  1 of 1 people found this helpful
                  • 6. Re: RF4. Obtaining URL parameters
                    sukharevd

                    Cool! Thank you!