10 Replies Latest reply on Aug 24, 2007 2:57 AM by mpulse

    URL parameter

    mpulse

      hello

      Is it possible to get an url parameter in a web page ?

      Or how do that :

      I'd like to add an id to the url => &id=123456

      and for loading the page I want to execute an action with the id in parameter's fonction.

      any ideas?

      thanks

        • 1. Re: URL parameter
          wise_guybg

          To have the parameter injected in a field inside your component you can do:

          @RequestParameter
          String id;


          • 2. Re: URL parameter
            mpulse

            I also try

            String id = (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id")
            

            But I just get a NULL value :s

            • 3. Re: URL parameter
              wise_guybg

              Here is an example of the use of RequestParameter

              import org.jboss.seam.annotations.Name;
              import org.jboss.seam.annotations.RequestParameter;
              
              @Name("detail")
              public class Detail
              {
              
               @RequestParameter
               Long entryId;
              
               public Long getEntryId()
               {
               return entryId;
               }
              
               public void setEntryId(Long entryId)
               {
               this.entryId = entryId;
               }
              
               public Entry getEntry()
               {
               return new Entry(entryId);
               }
              
              }


              • 4. Re: URL parameter
                wise_guybg

                In my Seam 2.0.0.BETA1 there is also a class Parameters (component name: org.jboss.seam.web.parameters)

                It has a getRequestParameters() method.

                • 5. Re: URL parameter
                  mpulse

                  I don't understand :(

                  first : i use

                  <s:link view="/smsInfo.xhtml" value="info"/>


                  for the link how add a parameter ? it must be visible in the url

                  with that link i have == > smsInfo.seam?cid=43

                  So how add id => #{msg.id}

                  Second : if a want that, it's for share page link so if the paramater is in the session in java :/ i don't see how it can work :/

                  the page will load a message by its ID.





                  • 6. Re: URL parameter
                    alexg79

                     

                    So how add id => #{msg.id}

                    <s:link view="/smsInfo.xhtml" value="info">
                     <f:param name="id" value="#{msg.id}"/>
                    </s:link>


                    • 7. Re: URL parameter
                      mpulse

                      thanks I arrive to pass id in parameter.

                      But i don't arrive to get it in java, always null value :(

                      • 8. Re: URL parameter
                        mpulse

                         

                        Parameters p = new Parameters();
                         Map<String,String[]> map = p.getRequestParameters();



                        send me null value

                        • 9. Re: URL parameter
                          alexg79

                           

                          thanks I arrive to pass id in parameter.

                          But i don't arrive to get it in java, always null value :(

                          You probably meant to use some other word here than "arrive", but I can't figure it out.
                          Anyway, you need this in the component you use on the destination page:
                          ...
                          @RequestParameter
                          private Integer id;
                          ...
                          

                          Use whatever type is appropriate in place of "Integer". Worked for me.
                          Alternatively, try reading up on page parameters in the Seam documentation.

                          • 10. Re: URL parameter
                            mpulse

                            Sorry for my bad english.

                            I add to page.xml =>

                            <page view-id="/smsInfo.xhtml" action="#{MyAction}"/>

                            And now it work with @RequestParameter

                            Thanks a lot.