The Source for Java Technology Collaboration
User: Password:



Carol McDonald

Carol McDonald's Blog

Sample Application using JSF, Seam 2.0, and Java Persistence APIs on Glassfish V2

Posted by caroljmcdonald on January 27, 2008 at 07:58 PM | Comments (11)

Sample Application using JSF, Seam 2.0, and Java Persistence APIs on Glassfish V2


I updated  this example  Sample Store Catalog app using JavaServer Faces, EJB, the Java Persistence APIs, and Seam 1.2 on Glassfish v1  to use Seam 2.0 on Glassfish V2. The Seam jar files needed to run on Glassfish have changed in Seam 2.0, (thanks to Cay Horstmann for pointing out which Seam 2.0 jars are needed)  nothing else in the example needs changing.  I also successfully tested Brian Leonard's Seam Refresh example with the Seam 2.0 jars, listed below, on Glassfish V2.

Download the Seam Sample Application Code


Configuration of the Application for Seam 2.0, JSF, JPA, running on Glassfish V2

First I recommend reading Brian Leonard's blog Seam Refresh .  I will summarize and update those steps here:

To Open and Test Run the seampagination Project:

  • Use the Resolve Reference Problems dialog to map the ejb and web modules to their project, which are subdirectories beneath the seampagination directory.
  • After the references are resolved, right-click the seampagination project and select Open Required Projects.
  • Right-click the seampagination-EJBModule and select Resolve Reference Problems:
    • browse to the Seam lib directory and select jboss-seam.jar and select Open. This should resove the reference to the following jars: jboss-seam.jar, hibernate.jar, hibernate-validator.jar, hibernate-annotations.jar, hibernate-commons-annotations.jar, javassist.jar, dom4j.jar, commons-logging.jar
  • Right-click the seampagination-WebModule and select Resolve Reference Problems:
    • Browse to the seampagination-ejb directory which is a sub-directory below the seampagination directory and select Open Project Folder.
    • Browse to the  jboss-seam-ui.jar found in Seam lib directory  and select Open Project Folder.  This should resove the reference to the following jars: jboss-seam-ui.jar and jboss-el.jar.
If you want to create your own Java EE application using Seam 2.0 on Glassfish V2 with Netbeans from scratch (read the steps in Brian Leonard's blog Seam Refresh but use the SEAM 2.0 jars listed here here):
  • Use Netbeans to create a new Enterprise Application
  • Right-click the Libraries node of the EJBModule project , choose Add Jar  and add these jars:
    • Seam \lib\jboss-seam.jar
    • Seam \lib\hibernate.jar
    • Seam \lib\hibernate-validator.jar
    • Seam \lib\hibernate-annotations.jar
    • Seam \lib\hibernate-commons-annotations.jar
    • Seam \lib\javassist.jar
    • Seam \lib\dom4j.jar
    • Seam \lib\commons-logging.jar
  • Right-click the Libraries node of the WebModule project ,  choose Add Jar  and add these jars:
    • your ejbModule
    • Seam \lib\jboss-seam-ui.jar
    • Seam \lib\jboss-el.jar
  • create an empty seam.properties file in the seampagination-EJBModule src\conf Folder.
  • add  the following phase listener to your faces-config.xml file under webpages web-inf:
    <lifecycle>
    <phase-listener>
    org.jboss.seam.jsf.SeamPhaseListener
    </phase-listener>
    </lifecycle>

  • add the following  context parameter to your web.xml file
    <context-param>
    <param-name>
    org.jboss.seam.core.init.jndiPattern
    </param-name>
    <param-value>
    java:comp/env/your ear name/#{ejbName}/local
    </param-value>
    </context-param>
  • add the following listener class to your web.xml file
    <listener>
    <listener-class>
    org.jboss.seam.servlet.SeamListener
    </listener-class>
    </listener>
  • For any session EJB's referenced from the web, add  EJB references to your web.xml, for example:
    <ejb-local-ref>
    <ejb-ref-name>your ear name/CatalogBean/local</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local-home/>
    <local>your package name.Catalog</local>
    <ejb-link>CatalogBean</ejb-link>
    </ejb-local-ref>
  • For any EJB's referenced from the web add  a Seam interceptor to the EJB, for example : @Interceptors({org.jboss.seam.ejb.SeamInterceptor.class})

References:





Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • http://blogs.sun.com/venky/entry/developing_seam_application_with_woodstock

    Uses seam with woodstock on netbeans.

    Posted by: venkatesh045 on January 27, 2008 at 09:21 PM

  • Venkatesh's example is interesting too, but what's special about Carol's is that she uses GlassFish's JPA implementation, not Hibernate. Nothing wrong with Hibernate, of course, but it is good to beat on TopLink to make sure it is up to snuff.
    Hopefully, the next version of GlassFish will auto-discover the beans, just like JBoss does.

    Posted by: cayhorstmann on January 28, 2008 at 09:31 PM

  • Hello! Did you try it with Spring 2.5? I get Validation Error (invalid stack size) when trying to use @Transactional and my aspect both under Spring 2.5. It seems that something wrong with CGLIB.
    I'm running my application with spring-agent and Spring JUnit integration annotation.

    Posted by: disa on February 07, 2008 at 02:07 PM

  • Yes I did implement a sample catalog app with Spring 2.5, see my previous blog entry. (but its not Seam and Spring together)

    Posted by: caroljmcdonald on February 07, 2008 at 02:12 PM

  • Hi,
    I implemented the example of Brian Leonard with glassfish and Seam 2. But if I press the button, I get the exception
    javax.el.MethodNotFoundException: Method not found: de.barmenia.muv.seamNB6.service.ManagerActionLocal_9501578.sayHallo()
    I'm very suprised at the _9501578-extension. Have you any idea to fix my problem?

    Posted by: pecabo on February 13, 2008 at 05:01 AM

  • Did you use the jars listed in this blog? Brian's example needs the jar in this blog to work. I don't know, you could ask in the Glassfish forum.

    Posted by: caroljmcdonald on February 13, 2008 at 05:13 AM

  • I did it à la


    If you want to create your own Java EE application using Seam 2.0 on Glassfish V2 with Netbeans from scratch (read the steps in Brian Leonard's blog Seam Refresh but use the SEAM 2.0 jars listed here here):

    from the scrath with the help of netbeans6 and addes the necessary entries and the jars listed above :)

    Posted by: pecabo on February 13, 2008 at 05:34 AM

  • Je ne sais pas

    Posted by: caroljmcdonald on February 13, 2008 at 05:40 AM

  • Bummer! But another question: if I use your example, I can't resolve the library problem: The project uses a class library called "restapi", but this class library was not found. What jars are bundled?

    Posted by: pecabo on February 13, 2008 at 05:55 AM

  • the restapi is added by netbeans 6. can you just remove this from the librairies? otherwise I will upload a version with this removed.

    Posted by: caroljmcdonald on February 13, 2008 at 06:09 AM

  • Yes, I can :)))) Thank you for the hint :)

    Posted by: pecabo on February 14, 2008 at 01:17 AM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds