4 Replies Latest reply on Apr 29, 2011 4:25 AM by sofie struyve

    SeamTest with Enum @RequestParameter

    Anton Bagchi Newbie

      Hi there,


      I'm trying to write some SeamTests for my application, but have run into a small problem.


      I need to set a parameter for the request which is an Enum value. This works fine in the actual application, but the SeamTest throws a
      java.lang.IllegalArgumentException: no converter for type: class MyEnum


      In my action I have the following request parameter:


      @RequestParameter 
      private MyEnum myParam



      In the xhtml page I have:


      <s:button id="save" value="Save" action="#{myAction.save}">
         <f:param name="myParam" value="ONE" />
      </s:button>



      And as part of the test case I have:


      @Override
      protected void beforeRequest() {
          setParameter("st", MyEnum.ONE.toString());
      }                    
      



      I've tried including a <s:convertEnum> in the xhtml, but no joy there. Has anyone had a similar problem - I imagine it's quite common, but can't seem to find any documentation for it.


      Cheers,


      Anton

        • 1. Re: SeamTest with Enum @RequestParameter
          Pete Muir Master

          Try using page parameters instead as they allow you to specify a converter.

          • 2. Re: SeamTest with Enum @RequestParameter
            Chad Retz Newbie

            I too suffer from this, but I don't understand your meaning by using page parameters. If I use setPageParameter from my test, it doesn't populate @RequestParameter. I wasn't wanting to change the code to support my tests. I have a piece of jsf [kinda] like so:



            <ui:repeat value="#{action.items}" var="item">
                <ice:outputText value="#{item.name}" />
                <ice:commandLink value="Do Something" action="#{action.doSomething}">
                    <f:param name="someEnum" value="#{item.someEnum}" />
                </ice:commandLink>
            </ui:repeat>




            w/


            @RequestParameter
            MyEnum someEnum;


            What would be the best way to test the doSomething action which needs these request parameters? I've tried to add a custom converter to Conversions in my test case and it didn't help. Thanks for any help you can give.

            • 3. Re: SeamTest with Enum @RequestParameter
              sofie struyve Newbie

              While trying to google a solution for this problem it seems nobody has a usefull answer.
              However, after a little trying I found a solution myself, and I believe that posting the answer here
              can be usefull for anyone still suffering this problem.


              I created a converter (MyEnumConverter  implements javax.faces.convert.Converter)


              and then used


                      request.getFacesContext().getApplication().addConverter(MyEnum.class, MyEnumConverter.class.getName());
                      request.setParameter("myEnumParam", MyEnum.VALUE.toString());
              



              where request is the FacesRequest (or NonFacesRequest)


              • 4. Re: SeamTest with Enum @RequestParameter
                sofie struyve Newbie

                While trying to google a solution for this problem it seems nobody has a usefull answer.
                However, after a little trying I found a solution myself, and I believe that posting the answer here
                can be usefull for anyone still suffering this problem.


                I created a converter (MyEnumConverter  implements javax.faces.convert.Converter)


                and then used


                        request.getFacesContext().getApplication().addConverter(MyEnum.class, MyEnumConverter.class.getName());
                        request.setParameter("myEnumParam", MyEnum.VALUE.toString());
                



                where request is the FacesRequest (or NonFacesRequest)