Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

If you're using Facelets (who isn't?) then you'll want to better handle exceptions in the same manner as Seam. By installing a custom facelet view handler you can delegate to the Seam exception handler.

Seam exception handling will not trap malformed xhtml. You'll receive error messages such as:

Error Parsing /home.xhtml: Error Traced[line: 18] Element type "h:outputText" must be followed by either attribute specifications, ">" or "/>"

In pages.xml you can create an exception for com.sun.facelets.FaceletException to redirect to your error handling page.

    <exception class="com.sun.facelets.FaceletException">
		<end-conversation/>
        <redirect view-id="/error.xhtml">
            <message>An unexpected error occurred. Our administrator has been notified.</message>
        </redirect>
    </exception>

On a development system without this entry you'll be redirected to the seam debug page. During development you may not even install this handler, but in production you want to catch as many errors as possible.

The custom facelet view handler

import java.io.IOException;
import java.util.Map;
import java.util.logging.Level;

import javax.el.ELException;
import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.exception.Exceptions;

import com.sun.facelets.FaceletViewHandler;

public class SeamFaceletViewHandler extends FaceletViewHandler {
	public SeamFaceletViewHandler(ViewHandler parent) {
		super(parent);
	}
	
	@Override
	protected void handleRenderException(FacesContext context, Exception exception) throws IOException, ELException, FacesException {
		log.severe(exception.getMessage());

		try {
        	Exceptions exceptions = (Exceptions)Component.getInstance("org.jboss.seam.exception.exceptions", ScopeType.APPLICATION);
        	exceptions.handle(exception);

        	return;
        } catch (Exception ex) {
        	log.log(Level.SEVERE, "Facelet view handler encountered an error redirecting to a custom error page", ex);
		}
        
        /* Defer to default handling if no seam exception handlers are found */
        super.handleRenderException(context, exception);
	}

	private HttpServletResponse getHttpResponseObject() {
		return (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
	}

	private Map<String, Object> getSessionMap() {
		return FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
	}

}

Modify faces-config.xml

Modify the view-handler in your faces-config.xml to the new handler above:

<view-handler>*your.project.path*.facelet.SeamFaceletViewHandler</view-handler>