[jboss-user] [JBoss Seam] - Seam debug page with ICEfaces

MarkCollette do-not-reply at jboss.com
Fri Dec 15 16:55:10 EST 2006


Hi, I work at ICEsoft, on both Facelets and Seam integration.  I ran into an issue with the Seam debug screen, as it works with ICEfaces.  Basically, none of the stock JSF components were rendering properly, because org.jboss.seam.debug.jsf.SeamDebugPhaseListener diretly uses Facelets, without using the ViewHandler mechanisms, which ICEfaces relies upon.

I think that the easiest approach will be to make a Seam  com.sun.facelets.impl.ResourceResolver  that knows how to get at the debug.xhtml file, and just use the existing  facelets.RESOURCE_RESOLVER  parameter to access it. No phase listener would be necessary, and the existing ViewHandler mechanisms would operate as usual to show the debug screen.

Some sort of chaining of ResourceResolvers should be done, so that apps with an existing ResourceResolver will work.  My preference would be for Facelets core to alter its use of the  facelets.RESOURCE_RESOLVER  parameter, to treat it as an ordered list of ResourceResolvers, much like how the  facelets.LIBRARIES  and  facelets.DECORATORS  parameters work.

In the immediate term, to simplify my proof of concept code, I will add a second parameter called  seam.RESOURCE_RESOLVER  which  org.jboss.seam.debug.jsf.SeamDebugResourceResolver  will delegate to.

So, to recap, here are some configuration examples:

Current way, with a custom ResourceResolver:

web.xml
<context-param>
  |   <param-name>facelets.RESOURCE_RESOLVER</param-name>
  |   <param-value>com.mycompany.CustomResourceResolver</param-value>
  | </context-param>
  | 

Short-term solution, with Seam debug ResourceResolver, and no other custom ResourceResolver:

web.xml
<context-param>
  |   <param-name>facelets.RESOURCE_RESOLVER</param-name>
  |   <param-value>org.jboss.seam.debug.jsf.SeamDebugResourceResolver</param-value>
  | </context-param>
  | 

Short-term solution, with Seam debug ResourceResolver, and a custom
ResourceResolver:

web.xml
<context-param>
  |   <param-name>facelets.RESOURCE_RESOLVER</param-name>
  |   <param-value>org.jboss.seam.debug.jsf.SeamDebugResourceResolver</param-value>
  | </context-param>
  | <context-param>
  |   <param-name>seam.RESOURCE_RESOLVER</param-name>
  |   <param-value>com.mycompany.CustomResourceResolver</param-value>
  | </context-param>
  | 

Potential long-term solution, with Seam debug ResourceResolver, and a custom ResourceResolver, chained:

web.xml
<context-param>
  |   <param-name>facelets.RESOURCE_RESOLVER</param-name>
  |  
  | <param-value>org.jboss.seam.debug.jsf.SeamDebugResourceResolver;com.mycompany.CustomResourceResolver</param-value>
  | </context-param>
  | 

To try out the proof-of-concept method (short-term), do the following:

1. Disable the SeamDebugPhaseListener by commenting out the lifecycle
phase-listener block in  src\debug\META-INF\faces-config.xml

2. Copy and paste the following Java source code, and save it to  src\debug\org\jboss\seam\debug\jsf\SeamDebugResourceResolver.java

3. Tell the web app about SeamDebugResourceResolver.  I added the following
block to both  examples\dvdstore\resources\WEB-INF\web.xml  and  examples\hibernate\resources\WEB-INF\web.xml

<context-param>
  |   <param-name>facelets.RESOURCE_RESOLVER</param-name>
  |   <param-value>org.jboss.seam.debug.jsf.SeamDebugResourceResolver</param-value>
  | </context-param>
  | 
4. Rebuild Seam so that the change to the phase-listener will take effect.

5. Build and deploy the web apps



##############################
SeamDebugResourceResolver.java
##############################

package org.jboss.seam.debug.jsf;
  | 
  | import java.io.IOException;
  | import java.net.URL;
  | 
  | import javax.faces.context.FacesContext;
  | import org.jboss.seam.core.Init;
  | 
  | import com.sun.facelets.impl.ResourceResolver;
  | import com.sun.facelets.impl.DefaultResourceResolver;
  | 
  | /**
  |  * Intercepts any request for a path like /debug.xxx and renders
  |  * the Seam debug page using facelets.
  |  *
  |  * @author Mark Collette
  |  */
  | public class SeamDebugResourceResolver implements ResourceResolver
  | {
  |    private final static String PARAM_RESOURCE_RESOLVER = "seam.RESOURCE_RESOLVER";
  | 
  |    private ResourceResolver delegate;
  | 
  |    public SeamDebugResourceResolver()
  |    {
  |       delegate = buildDelegateResourceResolver();
  |    }
  | 
  |    public URL resolveUrl(String path)
  |    {
  |       System.out.println("SeamDebugResourceResolver.resolveUrl()  path: " + path);
  |       if ( path!=null && path.startsWith("/debug.") && Init.instance().isDebug() )
  |       {
  |          URL url = SeamDebugResourceResolver.class.getClassLoader().getResource("META-INF/debug.xhtml");
  |          System.out.println("SeamDebugResourceResolver.resolveUrl()  url: " + url);
  |          return url;
  |       }
  |       return delegate.resolveUrl(path);
  |    }
  | 
  |    private ResourceResolver buildDelegateResourceResolver()
  |    {
  |       FacesContext ctx = FacesContext.getCurrentInstance();
  | 
  |       ResourceResolver resourceResolver = null;
  |       String paramResourceResolver =
  |          ctx.getExternalContext().getInitParameter(PARAM_RESOURCE_RESOLVER);
  |       if( paramResourceResolver != null && paramResourceResolver.length() > 0 )
  |       {
  |          try
  |          {
  |             Class resourceResolverClass = Class.forName(
  |                paramResourceResolver,
  |                true,
  |                Thread.currentThread().getContextClassLoader());
  |             resourceResolver = (ResourceResolver) resourceResolverClass.newInstance();
  |          }
  |          catch(Exception e)
  |          {
  |             throw new RuntimeException("Problem initializing Seam delegate ResourceResolver: " + paramResourceResolver, e);
  |          }
  |       }
  |       if( resourceResolver == null )
  |          resourceResolver = new DefaultResourceResolver();
  |       return resourceResolver;
  |    }
  | }


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3994352#3994352

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3994352



More information about the jboss-user mailing list