5 Replies Latest reply on Oct 14, 2009 6:21 PM by Enrico Drusiani

    To get the parameter values from Http Request

    Sinbad Kim Newbie

      Hi!


      I'm going to set multi links into one row using h:dataTable
      Each link has appropriate parameters, so i used s:link and f:param tags.


      In this case, how can i get this parameter in the session bean?


      Thanks for your help!

        • 1. Re: To get the parameter values from Http Request
          Eric H Novice

          Very easily!  In your bean, put something like:


          @RequestParameter private String myParameter;



          and your URL looks like:


          http://localhost:8080/my-page.seam?myParameter=Hello



          and it will work as expected.

          • 2. Re: To get the parameter values from Http Request
            Enrico Drusiani Newbie
            <blockquote>
            _Eric H wrote on Jul 28, 2008 09:02:_<br/>

            Very easily!  In your bean, put something like:

            `@RequestParameter private String myParameter;`

            and your URL looks like:

            `http://localhost:8080/my-page.seam?myParameter=Hello`

            and it will work as expected.
            </blockquote>

            hi!

            sorry to disturb, but that doesn't work for me.

            i've got my page at http://localhost:8080/app/home.seam

            and i access it as http://localhost:8080/app/home.seam?skin=testskin

            my pages.xml defines

            <page view-id="/home.xhtml" action="#{startup.test}" />

            startup is


            @Name("startup")
            @Scope(ScopeType.SESSION)
            public class StartupAction extends MyAction {
                   
            public static Logger logger;
                   
                   
            @RequestParameter private String skin;


            ...

            public String test(){
                           
            logger.info("calling startupAction.test");

            javax.faces.context.FacesContext facesContext = javax.faces.context.FacesContext.getCurrentInstance();
            ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();

            HttpServletRequest request = (HttpServletRequest)facesContext.getExternalContext().getRequest();

            Enumeration enumer = request.getParameterNames();
            while(enumer.hasMoreElements()){
                 logger.error("Request Parameters: "+ enumer.nextElement());
            }

            param2 = request.getParameter("skin");
                    
            logger.error("Parameter : " + param2);
            logger.error("Injected Parameter: " + skin);

                           
            return "";
            }


            but i can't get the parameter in either way. Any suggestion?

            Thanks a lot for your time
            • 3. Re: To get the parameter values from Http Request
              Nicklas Karlsson Master

              not sure if you can have the var private.


              You could also use ServletContexts.getInstance().getRequest()...

              • 4. Re: To get the parameter values from Http Request
                Enrico Drusiani Newbie

                ServletContexts seems something from Seam 2.x, i'm planning to upgrade my application, but i've got some deadlines before doing that :)


                is there a Seam 1.x equivalent?

                • 5. Re: To get the parameter values from Http Request
                  Enrico Drusiani Newbie
                  <blockquote>
                  _Nicklas Karlsson wrote on Sep 23, 2008 11:42:_<br/>

                  not sure if you can have the var private.

                  You could also use ServletContexts.getInstance().getRequest()...
                  </blockquote>

                  hi!

                  i've upgraded to Seam 2 and your suggestion works perfectly. But if i change the parameter on the URL and hit the enter button, the page doesn't reload. it doesn't even enter the action method.

                  i tried adding  " on-postback="true" " to the action in pages.xml but nothing changed.

                  any suggestion?