Skip to content

Running the SEAM Booking demo on Glassfish & Netbeans

July 5, 2006

For those of you interested in playing with JBoss
SEAM
on Glassfish, here are some tips which will hopefully get
you going.




Disclaimer: I got this working, but I don‘t claim that my
hacks are the right solution. There seem to be a few quirks/bugs in
the booking demo that are problematic on Glassfish.



Before proceeding you will want to read Brian
and Roger’s
blogs on the subject.



Here are the modifications that I made to the demo (note, no
modifications to SEAM 1.0.1. are required):




Create a Netbeans enterprise project


You might want to use Brian‘s Netbeans project as a starting
point, or alternatively (the route I chose) – create a Netbeans
enterprise project and import the SEAM booking demo code into the
project.


Update ejb-jar.xml


The ejb-jar from the example contained the binding declaration,
but was missing the interceptor definition (I gather JBoss App Server
does not require this). This is what my modified ejb-jar.xml looks
like:



<ejb-jar>
<assembly-descriptor>
<interceptors>
<interceptor>
<interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
<!– use other elements as per your requirement–>
</interceptor>
<!– define other interceptors here–>
</interceptors>
<interceptor-binding>
<ejb-name>*</ejb-name>
<interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
</interceptor-binding>
</assembly-descriptor>
</ejb-jar>


Update web.xml


The web.xml setup is esentially as per the SEAM documentation with
the caveat that Glassfish requires you to declare local ref‘s
to your session beans (There is probably a good reason for this –
but JBoss seems to get away without these declarations). Here is the
modified web.xml (note that I named my project “reservit”
and this is reflected in the ejb local ref‘s. You will need to
update this to match your project deployment descriptor).



<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!– Seam –>
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<!– Propagate conversations across redirects –>
<filter>
<filter-name>Seam Redirect Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamRedirectFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Redirect Filter</filter-name>
<url-pattern>*.seam</url-pattern>
</filter-mapping>
<!– JSF –>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<!– Todo: this is already provided in the init code – not sure if it is needed
–>
<context-param>
<param-name>org.jboss.seam.core.init.jndiPattern</param-name>
<param-value>java:comp/env/reservit/#{ejbName}/local</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!– Faces Servlet Mapping –>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.seam</url-pattern>
</servlet-mapping>
<ejb-local-ref>
<ejb-ref-name>reservit/BookingListAction/local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.BookingList</local>
<ejb-link>BookingListAction</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>reservit/RegisterAction/local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.Register</local>
<ejb-link>RegisterAction</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>reservit/ChangePasswordAction/local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.ChangePassword</local>
<ejb-link>ChangePasswordAction</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>reservit/HotelBookingAction/local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.HotelBooking</local>
<ejb-link>HotelBookingAction</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>reservit/HotelSearchingAction/local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.HotelSearching</local>
<ejb-link>HotelSearchingAction</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>reservit/LoginAction/local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.Login</local>
<ejb-link>LoginAction</ejb-link>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>reservit/LogoutAction/local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>org.jboss.seam.example.booking.Logout</local>
<ejb-link>LogoutAction</ejb-link>
</ejb-local-ref>
</web-app>


Update the JPQL queries.


I found the booking example queries would not parse correctly with
the Glassfish/Toplink persistence manager [note: you need to update
the persistence.xml file to use Glassfish/Toplink]. I presume this is
a standard‘s thing – but I don‘t know which
implementation is correct. You will need to change queries of the
form:


bookings = em.createQuery("from Booking b
where b.user.username = :username order by b.checkinDate")


To this:

bookings = em.createQuery("select b
from Booking b where b.user.username = :username order by
b.checkinDate")


Fix the s:link tags


I found that the linkStyle=“button” attribute of the
SEAM link tag causes XML parsing errors. This could be a facelets
and/or JSF 1.2 bug? (suggestions welcome). I removed this attribute –
which fixes the XML parsing error at the expense of not rendering the
link as a button. Change this:



<s:link value="Cancel" action="login" linkStyle="button" buttonClass="button"/>


To this:



<s:link value="Cancel" action="login" buttonClass="button"/>


Fix XML parsing wierdness.


This falls into the not-really-sure-what-I-am-doing category. I
found a lot of parsing errors with the facelet .xhtml files. In
particular:



  1. I found the DOCTYPE header on most
    of the .xhtml files caused problems. This appears to be related to
    the facelets templating mechanism. Getting rid of the header made
    this problem go away.


  2. Non breaking spaces such as
    amp;nbsp; or amp;#160; caused parsing problems. Once again –
    this looks like some kind of templating problem.


  3. Beware of comments. While experimenting I would often put
    suspect code in XML comments. That is, until I realized the comments
    are parsed by the facelets template engine, causing runtime parsing
    errors.



If you have suggestions please leave a comment!

Advertisements
One Comment
  1. Asaf permalink
    July 6, 2006 4:19 am

    Hey,
    Looks good,
    I was wondering, did you manage to port the ‘selectItems’ dataBinder registration sample?
    It only works for Jboss, in glassfish it fails, I was happy to see this working, many components are dependent on the ‘selectItems’ option….
    here’s the link for the app, just in case 🙂
    http://wiki.jboss.org/wiki/attach?page=JBossSeam%2Fselectitemsregexample.zip

    Cheers.

Comments are closed.

%d bloggers like this: