3 Replies Latest reply on Apr 2, 2008 12:41 PM by Pete Muir

    Out annotation and page parameter

    Hussein Baghdadi Novice

      Hi.
      Consider this code snippet:


      private String isbn;
      @Out(required = true)
      private Book book;
      
      public String loadBook() {
        book = findBook(isbn);
      }



      isbn is a page parameter.


      I got an exception during running the test class for the previous code indicating that an @Out property can't be null.


      My guess is that after setting the isbn page parameter via setIsbn(String) method, Seam is trying to outject the book property which it is null at this point, right?


      Thanks.

        • 1. Re: Out annotation and page parameter
          Pete Muir Master

          One more time. PLEASE PROVIDE RELEVANT CODE SNIPPETS.

          • 2. Re: Out annotation and page parameter
            Hussein Baghdadi Novice
            @Local
            public interface IBook {
            
                public String loadBook();
            
                public void setIsbn(String isbn);
            
                public String getIsbn();
            
                public Book getLoadedBook();
            
            }




            @Stateless
            @Name("bookAction")
            public class BookAction implements IBook {
            
                @PersistenceContext
                private EntityManager entityManager;
            
                private String isbn;
            
                @Out(scope = ScopeType.EVENT, required = true)
                private Book book;
            
                @TransactionAttribute(TransactionAttributeType.SUPPORTS)
                public String loadBook() {
                    book = (Book) entityManager.createNamedQuery("findBookByIsbn").setParameter("isbn", isbn).getSingleResult();
                    return StringConstants.SUCCESS;
                }
            
                public void setIsbn(String isbn) {
                    this.isbn = isbn;
                }
            
                public String getIsbn() {
                    return this.isbn;
                }
            
                public Book getLoadedBook() {
                    return book;
                }
            
            }
            



                <page view-id="/book.xhtml" action="#{bookAction.loadBook}">
                    <param name="isbn" value="#{bookAction.isbn}" required="true"/>
                </page>




            public class BookTest extends SeamTest {
                @Test
                public void loadBookTest() throws Exception {
            
                    new NonFacesRequest("/book.xhtml") {
                        @Override
                        protected void beforeRequest() {
                            setParameter("isbn", "0321146182");
                        }
            
                        @Override
                        protected void renderResponse() throws Exception {
                            Book book = (Book) Contexts.getEventContext().get("book");
                            assert book != null;
                            assert book.getTitle().equals("J2EE Web Services");
                        }
                    }.run();
            
                }
            }
            


            • 3. Re: Out annotation and page parameter
              Pete Muir Master

              Correct. Page parameters are set before page actions are called.