11 Replies Latest reply on Jul 5, 2006 2:40 PM by bkyrlach

    Request parameter arrays?

    bkyrlach

      When submitting a form that has a multi-select, I'm noticing that @RequestParameter is only ever getting the first value of the multi-select.

      For example, let's say I have the following html snippet...


      School 1
      School 2
      ...
      ...
      ...


      And the following SLSB...

      @Stateless
      @Name("infozapAction")
      @Interceptors(SeamInterceptor.class)
      public class InfozapActionImpl implements InfozapAction
      {
      @RequestParameter
      private String[] schoolList;

      @Out
      private InfoZapDTO izdto;

      public void createInfoZapDTO()
      {
      System.out.println("Length = " + schoolList.length);
      izdto = new InfoZapDTO(schoolList);
      }
      }

      In the console I get something like...

      08:23:51,101 INFO [STDOUT] Length = 1

      And the array only contains the first "shoolList" parameter in the request. Is there a way around this?

        • 1. Re: Request parameter arrays?
          pmuir

          You could try getting the value programmatically

          @In FacesContext facesContext
          ...
          
          facesContext.getExternalContext().getRequestParameterMap().get("schoolList");
          


          Alternatively why not use a JSF component (selectManyListbox) and inject selection as a list

          • 2. Re: Request parameter arrays?
            bkyrlach

            Thanks for your helpful reply. I didn't know how to get access to the actual request object. Unfortunantly, I can't use a faces component, as I'm not allowed to rewrite the page that the request comes from. I do think that @RequestParamater should support a mutli-select however. It seems silly that what I tried originally didn't work.

            Oh well. Thanks again for your help.

            • 3. Re: Request parameter arrays?
              bkyrlach

              Well, trying the above code results in an exception being thrown. I think that the faces context might not be available yet. Basically, I'm using pages.xml to require a SLSB method to be invoked before my my page loads. Inside that SLSB method, I'm trying to get the "schoolList" request parameter. Anyways, here's the exception that's thrown...

              12:50:48,523 ERROR [PhaseListenerManager] Exception in PhaseListener RENDER_RESPONSE(6) beforePhase.
              javax.faces.el.EvaluationException: Exception while invoking expression #{infozapAction.createInfoZapDTO}
              at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:153)
              at org.jboss.seam.core.Pages.callAction(Pages.java:156)
              at org.jboss.seam.core.Pages.callAction(Pages.java:138)
              at org.jboss.seam.jsf.AbstractSeamPhaseListener.callPageActions(AbstractSeamPhaseListener.java:125)
              at org.jboss.seam.jsf.AbstractSeamPhaseListener.beforeRender(AbstractSeamPhaseListener.java:100)
              at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:47)
              at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersBefore(PhaseListenerManager.java:70)
              at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:373)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
              at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
              at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:54)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:174)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
              at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
              at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
              at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
              at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:744)
              at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:674)
              at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:866)
              at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
              at java.lang.Thread.run(Thread.java:595)
              Caused by: javax.ejb.EJBException: org.jboss.seam.RequiredException: In attribute requires value for component: infozapAction.context
              at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
              at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
              at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:192)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
              at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
              at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
              at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
              at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
              at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
              at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:181)
              at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
              at $Proxy338.createInfoZapDTO(Unknown Source)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:585)
              at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
              ... 33 more
              Caused by: org.jboss.seam.RequiredException: In attribute requires value for component: infozapAction.context
              at org.jboss.seam.Component.getInstanceToInject(Component.java:1230)
              at org.jboss.seam.Component.injectFields(Component.java:892)
              at org.jboss.seam.Component.inject(Component.java:696)
              at org.jboss.seam.interceptors.BijectionInterceptor.bijectTargetComponent(BijectionInterceptor.java:30)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:585)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
              at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
              at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
              at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRunningConversation(ConversationInterceptor.java:68)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:585)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
              at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
              at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
              at org.jboss.seam.interceptors.BusinessProcessInterceptor.manageBusinessProcessContext(BusinessProcessInterceptor.java:60)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:585)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
              at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
              at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
              at org.jboss.seam.interceptors.RemoveInterceptor.removeIfNecessary(RemoveInterceptor.java:39)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:585)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
              at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
              at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
              at org.jboss.seam.ejb.SeamInterceptor.aroundInvokeInContexts(SeamInterceptor.java:73)
              at org.jboss.seam.ejb.SeamInterceptor.aroundInvoke(SeamInterceptor.java:45)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:585)
              at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:120)
              at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:62)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
              at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
              at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
              at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
              ... 53 more

              • 4. Re: Request parameter arrays?
                bkyrlach

                Nevermind, I'm a dork. I forgot that Seam bases injection off of the name of the private member variable. I should have more carefully copied your code.

                Remember class, shorcuts == bad.

                :-/

                • 5. Re: Request parameter arrays?
                  pmuir

                   

                  Caused by: org.jboss.seam.RequiredException: In attribute requires value for component: infozapAction.context


                  is the cause of your exception. NB you can also access the FacesContext as

                  FacesContext ctx = FacesContext.getCurrentInstance();
                  


                  • 6. Re: Request parameter arrays?
                    pmuir

                    Yeah, facesContext is the name of a provided seam component

                    • 7. Re: Request parameter arrays?
                      pmuir

                      If getting it via FacesContext works (for a multi select) but not via @RequestParameter I suggest you file a bug in Jira.

                      • 8. Re: Request parameter arrays?
                        bkyrlach

                        Thank you so much for your help. The way you suggested getting it didn't quite work, but the following did.

                        ServletRequest req = (ServletRequest)facesContext.getExternalContext().getRequest();
                        String schoolList[]=req.getParameterValues("schoolList");

                        Anyways, I'll definitely file a bug report. Thanks again for your help.

                        • 9. Re: Request parameter arrays?
                          bkyrlach

                          Bug entered as JBSEAM-291. I probably didn't file it quite correctly. Oh well.

                          • 10. Re: Request parameter arrays?
                            gavin.king

                            I'll try to get that done.

                            • 11. Re: Request parameter arrays?
                              bkyrlach

                              This is now fixed in CVS.