3 Replies Latest reply on Mar 16, 2008 10:53 AM by Hussein Baghdadi

    Setting page parameter isn't working

    Hussein Baghdadi Novice

      Hi.


      I'm having troubles with integeration tests for my Seam EAR application (the appliction's skeleton is generated via seam-gen)


      pages.xml


          <page view-id="/category.xhtml" action="#{categoryAction.listBooksByCategoryName}">
              <param name="name" value="#{category.name}" required="true"/>
          </page>


      Category.java


      @Stateless
      @Name("categoryAction")
      public class CategoryAction implements ICategory {
      
          @PersistenceContext
          private EntityManager entityManager;
      
          @Out(scope = ScopeType.EVENT, required = true)
          private List listOfBooks;
      
          private Category category;
          @TransactionAttribute(TransactionAttributeType.SUPPORTS)
          public String listBooksByCategoryName() {
              listOfBooks = entityManager.createNamedQuery("findBooksByCategoryName").setParameter("name", category.getName()).
                      getResultList();
              return StringConstants.SUCCESS;
          }
      }


      Category.java


      @Entity
      @Name("category")
      @BatchSize(size = 5)
      @NamedQueries({
      @NamedQuery(name = "findBooksByCategoryName",
              query = "select book from Category category join category.books book where category.name = :name")
              })
      public class Category implements Serializable {


      CategoryTest.java


      public class CategoryTest extends SeamTest {
          @Test
          public void listBooksByCategoryTest() throws Exception {
      
              new NonFacesRequest("/category.xhtml") {
                  @Override
                  protected void beforeRequest() {
                      setParameter("name", "Java");
                  }
      
                  @Override
                  protected void renderResponse() throws Exception {
                      List list = (List) Contexts.getEventContext().get("listOfBooks");
                      assert list != null;
                  }
              }.run();
      
          }
      }


      But upon running the test I got a NullPointerException from category.getName() from CategoryAction class.
      It seems that an instane of Category class doesn't get created.
      Any ideas?


      One more thing:


      Is it possible to have:


      private String category;
      instead of:


      private Category category;


      in CategoryAction.java?


      (Ubuntu 7.10 and Seam 2.0.0GA)


      Thanks for help and time.

        • 1. Re: Setting page parameter isn't working
          mars1412 Apprentice

          try this:


          <param name="name" value="#{categoryAction.categoryName}" required="true"/>



          on CategoryAction use this:


          private String categoryName;



          u should also consider passing the the category Id (if you have one..)

          • 2. Re: Setting page parameter isn't working
            Hussein Baghdadi Novice

            I tried this:


                <page view-id="/category.xhtml" action="#{categoryAction.listBooksByCategoryName}">
                    <param name="name" value="#{categoryAction.categoryName}" required="true"/>
                </page>



            And CategoryAction.java


            private String categoryName;


            But I got the same error, no value doesn't its value set.


            What about annotating categoryName as:



            @RequestParameter
            private String categoryName;



            This time the value is set but I got this exception:


               [testng] WARN  12-03 11:42:56,909 (Param.java:convertValueFromString:208)  -could not create converter for: name
               [testng] javax.el.PropertyNotFoundException: The class 'org.javassist.tmp.java.lang.Object_$$_javassist_0' does not have the property 'categoryName'.
               [testng]     at javax.el.BeanELResolver.getBeanProperty(BeanELResolver.java:574)
               [testng]     at javax.el.BeanELResolver.getType(BeanELResolver.java:230)
               [testng]     at javax.el.CompositeELResolver.getType(CompositeELResolver.java:215)
               [testng]     at javax.el.CompositeELResolver.getType(CompositeELResolver.java:215)
               [testng]     at org.jboss.el.parser.AstPropertySuffix.getType(AstPropertySuffix.java:30)
               [testng]     at org.jboss.el.parser.AstValue.getType(AstValue.java:29)
               [testng]     at org.jboss.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:174)
               [testng]     at org.jboss.seam.core.Expressions$1.getType(Expressions.java:127)
               [testng]     at org.jboss.seam.navigation.Param.getConverter(Param.java:64)
               [testng]     at org.jboss.seam.navigation.Param.convertValueFromString(Param.java:203)
               [testng]     at org.jboss.seam.navigation.Pages.convertAndValidateStringValuesInPageContext(Pages.java:744)
               [testng]     at org.jboss.seam.navigation.Pages.postRestore(Pages.java:393)
               [testng]     at org.jboss.seam.jsf.SeamPhaseListener.postRestorePage(SeamPhaseListener.java:528)
               [testng]     at org.jboss.seam.jsf.SeamPhaseListener.afterRestoreView(SeamPhaseListener.java:374)
               [testng]     at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:211)
               [testng]     at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:184)
               [testng]     at org.jboss.seam.mock.BaseSeamTest$Request.restoreViewPhase(BaseSeamTest.java:772)
               [testng]     at org.jboss.seam.mock.BaseSeamTest$Request.emulateJsfLifecycle(BaseSeamTest.java:586)
               [testng]     at org.jboss.seam.mock.BaseSeamTest$Request.access$300(BaseSeamTest.java:185)
               [testng]     at org.jboss.seam.mock.BaseSeamTest$Request$2.doFilter(BaseSeamTest.java:519)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
               [testng]     at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               [testng]     at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               [testng]     at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               [testng]     at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
               [testng]     at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
               [testng]     at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               [testng]     at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               [testng]     at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               [testng]     at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
               [testng]     at org.jboss.seam.mock.BaseSeamTest$Request.run(BaseSeamTest.java:514)
               [testng]     at test.CategoryTest.listBooksByCategoryTest(CategoryTest.java:19)
               [testng]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               [testng]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
               [testng]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               [testng]     at java.lang.reflect.Method.invoke(Method.java:597)
               [testng]     at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:604)
               [testng]     at org.testng.internal.Invoker.invokeMethod(Invoker.java:470)
               [testng]     at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:564)
               [testng]     at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:830)
               [testng]     at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
               [testng]     at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
               [testng]     at org.testng.TestRunner.runWorkers(TestRunner.java:678)
               [testng]     at org.testng.TestRunner.privateRun(TestRunner.java:624)
               [testng]     at org.testng.TestRunner.run(TestRunner.java:495)
               [testng]     at org.testng.SuiteRunner.runTest(SuiteRunner.java:300)
               [testng]     at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:295)
               [testng]     at org.testng.SuiteRunner.privateRun(SuiteRunner.java:275)
               [testng]     at org.testng.SuiteRunner.run(SuiteRunner.java:190)
               [testng]     at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:792)
               [testng]     at org.testng.TestNG.runSuitesLocally(TestNG.java:765)
               [testng]     at org.testng.TestNG.run(TestNG.java:699)
               [testng]     at org.testng.TestNG.privateMain(TestNG.java:824)
               [testng]     at org.testng.TestNG.main(TestNG.java:802)
               [testng] Hibernate: 
               [testng]     select
               [testng]         books1_.id as id5_,
               [testng]         books1_.category_id as category13_5_,
               [testng]         books1_.description as descript2_5_,
               [testng]         books1_.discount as discount5_,
               [testng]         books1_.image_path as image4_5_,
               [testng]         books1_.isbn as isbn5_,
               [testng]         books1_.number_of_pages as number6_5_,
               [testng]         books1_.price as price5_,
               [testng]         books1_.publisher_id as publisher12_5_,
               [testng]         books1_.releasing_date as releasing8_5_,
               [testng]         books1_.title as title5_,
               [testng]         books1_.toc_path as toc10_5_,
               [testng]         books1_.optlock as optlock5_ 
               [testng]     from
               [testng]         Category category0_ 
               [testng]     inner join
               [testng]         Book books1_ 
               [testng]             on category0_.id=books1_.category_id 
               [testng]     where
               [testng]         category0_.name=?
               [testng] WARN  12-03 11:42:57,116 (SeamPhaseListener.java:<init>:92)  -There should only be one Seam phase listener per application
               [testng] WARN  12-03 11:42:58,984 (RuleBasedIdentity.java:initSecurityContext:72)  -no security rule base available - please install a RuleBase with the name 'securityRules' if permission checks are required.
               [testng] Hibernate: 
               [testng]     select
               [testng]         book0_.id as id5_,
               [testng]         book0_.category_id as category13_5_,
               [testng]         book0_.description as descript2_5_,
               [testng]         book0_.discount as discount5_,
               [testng]         book0_.image_path as image4_5_,
               [testng]         book0_.isbn as isbn5_,
               [testng]         book0_.number_of_pages as number6_5_,
               [testng]         book0_.price as price5_,
               [testng]         book0_.publisher_id as publisher12_5_,
               [testng]         book0_.releasing_date as releasing8_5_,
               [testng]         book0_.title as title5_,
               [testng]         book0_.toc_path as toc10_5_,
               [testng]         book0_.optlock as optlock5_ 
               [testng]     from
               [testng]         Book book0_ 
               [testng]     order by
               [testng]         book0_.title limit ?
               [testng] PASSED: listNewTitlesTest
               [testng] FAILED: listBooksByCategoryTest
               [testng] java.lang.AssertionError: javax.el.PropertyNotFoundException: The class 'org.javassist.tmp.java.lang.Object_$$_javassist_0' does not have the property 'categoryName'.
               [testng]     at org.jboss.seam.mock.BaseSeamTest$Request.onException(BaseSeamTest.java:475)
               [testng]     at org.jboss.seam.mock.BaseSeamTest$Request$2.doFilter(BaseSeamTest.java:526)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
               [testng]     at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               [testng]     at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               [testng]     at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               [testng]     at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
               [testng]     at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
               [testng]     at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               [testng]     at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               [testng]     at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
               [testng]     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               [testng]     at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
               [testng]     at org.jboss.seam.mock.BaseSeamTest$Request.run(BaseSeamTest.java:514)
               [testng]     at test.CategoryTest.listBooksByCategoryTest(CategoryTest.java:19)
               [testng] Caused by: javax.el.PropertyNotFoundException: The class 'org.javassist.tmp.java.lang.Object_$$_javassist_0' does not have the property 'categoryName'.
               [testng]     at javax.el.BeanELResolver.getBeanProperty(BeanELResolver.java:574)
               [testng]     at javax.el.BeanELResolver.getValue(BeanELResolver.java:280)
               [testng]     at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
               [testng]     at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
               [testng]     at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
               [testng]     at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
               [testng]     at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
               [testng]     at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:112)
               [testng]     at org.jboss.seam.navigation.Param.getStringValueFromModel(Param.java:132)
               [testng]     at org.jboss.seam.navigation.Pages.updateStringValuesInPageContextUsingModel(Pages.java:820)
               [testng]     at org.jboss.seam.jsf.SeamStateManager.saveView(SeamStateManager.java:86)
               [testng]     at org.jboss.seam.mock.BaseSeamTest$Request.renderResponsePhase(BaseSeamTest.java:631)
               [testng]     at org.jboss.seam.mock.BaseSeamTest$Request.emulateJsfLifecycle(BaseSeamTest.java:611)
               [testng]     at org.jboss.seam.mock.BaseSeamTest$Request.access$300(BaseSeamTest.java:185)
               [testng]     at org.jboss.seam.mock.BaseSeamTest$Request$2.doFilter(BaseSeamTest.java:519)
               [testng]     ... 40 more
               [testng] ... Removed 22 stack frames
               [testng] 
               [testng] ===============================================
               [testng]     ArmadaBookStore
               [testng]     Tests run: 2, Failures: 1, Skips: 0
               [testng] ===============================================
               [testng] 
               [testng] 
               [testng] ===============================================
               [testng] ArmadaBookStore
               [testng] Total tests run: 2, Failures: 1, Skips: 0
               [testng] ===============================================
               [testng] 
            


            If you can't hear me, I'm saying huh!!


            I'm becoming bald soon....


            Thank you for your help.




            • 3. Re: Setting page parameter isn't working
              Hussein Baghdadi Novice

              I switched the application to a WAR (POJOs not EJB3), the page action and page parameter is working without any problem, even without @RequestParameter.


              Any help will be great.