4 Replies Latest reply on Jul 23, 2010 7:05 AM by Christoph Brill

    Seam and non-Seam application classloader issues

    Christoph Brill Newbie

      I'm trying to use a Seam-based application and a non-seam application on Apache Tomcat 6. The Seam JARs itself are placed in the common classloader of the tomcat so they are available for all applications (if needed). From my understanding this is basically the same as placing them in the same EAR on JBoss, as the classloader hierarchy will be similar (the EAR classloader is more or less what I'm using the common classloader for).


      As far as I understand Seam registers itself with JSF/Facelets using the SeamViewHandler class. This is an issue for as any other JSF/Facelets application not using Seam does not work any more. I get the following stacktrace (heavily reduced to the line causeing the problem):


      Caused by: java.lang.NullPointerException
      at org.jboss.seam.jsf.SeamViewHandler.calculateLocale(SeamViewHandler.java:55)


      LocaleSelector.instance() does return a null value causing the exception. From what I've read in other sources(1) it happens because I don't specify any default locale in faces-config.xml. This is not an option as I'm running applications not written by myself. It is also not an option to package seam with the WAR file of my application as that kill hot deployments (Seam doesn't like to be reloaded from what I can tell).


      Can anyone tell me how to properly fix this? Btw: This testing has been done using Seam 2.2.1.CR1


      Regards,
      Christoph


      HalloWorld using Seam with the IDE Netbeans 6.5 on Glassfish
      (1)

        • 1. Re: Seam and non-Seam application classloader issues
          Christoph Brill Newbie

          From what I could find out the SeamPhaseListener (loaded from jboss-seam-2.2.1.CR1.jar!/META-INF/faces-config.xml) always registers itself for any JSF/Facelets application.


          So I think this listener should check if an application for is a seam application, before doing anything.

          • 2. Re: Seam and non-Seam application classloader issues
            Christoph Brill Newbie
            From dceeb82672a159acae35d51b502bcff3a24a8c38 Mon Sep 17 00:00:00 2001
            From: Christoph Brill <egore911@...>
            Date: Fri, 23 Jul 2010 11:10:25 +0200
            Subject: [PATCH] Stop the PhaseListener doing work on non-seam applications

            ---
            .../java/org/jboss/seam/jsf/SeamPhaseListener.java |   13 +++++++++++++
            1 files changed, 13 insertions(+), 0 deletions(-)

            diff --git a/src/main/java/org/jboss/seam/jsf/SeamPhaseListener.java b/src/main/java/org/jboss/seam/jsf/SeamPhaseListener.java
            index d13aeea..c4eb5d3 100644
            --- a/src/main/java/org/jboss/seam/jsf/SeamPhaseListener.java
            +++ b/src/main/java/org/jboss/seam/jsf/SeamPhaseListener.java
            @@ -21,6 +21,7 @@ import javax.faces.context.FacesContext;
            import javax.faces.event.PhaseEvent;
            import javax.faces.event.PhaseId;
            import javax.faces.event.PhaseListener;
            +import javax.servlet.ServletContext;
            import javax.servlet.http.HttpServletRequest;

            import org.jboss.seam.Seam;
            @@ -105,6 +106,12 @@ public class SeamPhaseListener implements PhaseListener
                {
                   log.trace( "before phase: " + event.getPhaseId() );

            +      // Skip non-seam applications
            +      ServletContext servletContext = (ServletContext) event.getFacesContext().getExternalContext().getContext();
            +      if (servletContext.getAttribute(Seam.VERSION) == null) {
            +          return;
            +      }
            +
                   FacesLifecycle.setPhaseId( event.getPhaseId() );

                   try
            @@ -184,6 +191,12 @@ public class SeamPhaseListener implements PhaseListener
                {
                   log.trace( "after phase: " + event.getPhaseId() );

            +      // Skip non-seam applications
            +      ServletContext servletContext = (ServletContext) event.getFacesContext().getExternalContext().getContext();
            +      if (servletContext.getAttribute(Seam.VERSION) == null) {
            +          return;
            +      }
            +
                   try
                   {
                      raiseEventsAfterPhase(event);
            --
            1.7.0.4
            • 3. Re: Seam and non-Seam application classloader issues
              Christoph Brill Newbie

              The patch provided above against Seam 2.2.1.CR1 stops the phase listener from doing anything on non-seam applications. I patched my local jboss-seam-2.2.1.CR1.jar and it works this way.