2 Replies Latest reply on Aug 31, 2008 11:32 AM by pmuir

    RequestParameter versus <param>

    trincao
      Hi Seam experts!

      I have a question for you.
      What are the differences between using the @RequestParameter annotation and <param /> on pages.xml?
      I know they are supposed to be the same, but I have detected some differences between them.

      For instance:

      Setting the <page /> tag on pages.xml it sets the serviceId variable via the setter



      `
        <page view-id="/service_show.xhtml" action="#{serviceSearch.doSetSelectedService}">
          <param name="srvid" value="#{serviceSearch.serviceId}" />
          <navigation>
            <rule if-outcome="addComment">
              <redirect view-id="/service_show.xhtml" />
            </rule>
          </navigation>
        </page>
      `


      Whereas using @RequestParameter, the serviceId is set directly (not via the setter):

      `
              @RequestParameter(value = "srvid")
              String serviceId;
      `


      Another difference is that when using @RequestParameter with the following form I get the exception bellow, whereas using <param /> it works fine.
      It seems that when using @RequestParameter the variable is set later thant when using <param />.

      `
        <h:form id="addServiceCommentForm">
          <h:inputTextarea id="comments" value="#{serviceSearch.newServiceComment.text}" />
          <br />
          <h:commandLink id="submit" value="Create" action="#{serviceSearch.createServiceComment}">
          </h:commandLink>
        </h:form>
      `

      What are there other differences? Have you got an idea why this is happening?
      Thank you for your time.

      Gonçalo

      2008-08-29 19:08:54,764 FATAL [javax.enterprise.resource.webcontainer.jsf.application] java.lang.NumberFormatException: null
      javax.faces.el.EvaluationException: java.lang.NumberFormatException: null
              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
              at javax.faces.component.UICommand.broadcast(UICommand.java:383)
              at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:184)
              at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:162)
              at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:350)
              at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
              at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
      ...
      Caused by: java.lang.NumberFormatException: null
              at java.lang.Long.parseLong(Long.java:372)
              at java.lang.Long.parseLong(Long.java:461)
              at com.something.portal.web.ServiceSearchAction.createServiceComment(ServiceSearchAction.java:115)
        • 1. Re: RequestParameter versus <param>
          gjeudy

          Your exception might be because no value is being set? i.e. RequestParameter is not being propagated ?


          <h:commandLink id="submit" value="Create" action="#{serviceSearch.createServiceComment}">
              </h:commandLink>
          



          you don't put a parameter on your commandLink so I don't see how you can have the request parameter set while executing createServiceComment. You can try setting it in pages.xml or use f:param tag inside commandLink.

          • 2. Re: RequestParameter versus <param>
            pmuir

            Goncalo Trincao wrote on Aug 29, 2008 20:31:


            What are the differences between using the @RequestParameter annotation and <param /> on pages.xml?
            I know they are supposed to be the same, but I have detected some differences between them.



            No, they are not supposed to be the same, read the docs more carefully.