/* * MappingViewHandler.java * * Created on 2 Οκτώβριος 2007, 7:52 μμ * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package gr.xfrag.faces.mapping; import java.io.IOException; import java.util.Locale; import javax.faces.FacesException; import javax.faces.application.ViewHandler; import javax.faces.component.UIViewRoot; import javax.faces.context.FacesContext; /** * This class in combination with the MappingFilter will take care of the mapping. * @author Chris Fragoulides */ public class MappingViewHandler extends ViewHandler{ /** * The original handler we are extending. */ private ViewHandler prevHandler = null; /** Creates a new instance of MappingViewHandler. By including * a parameter of the same type, we encourage the JSF framework * to pass a reference of the previously used ViewHandler. This way * we can use all the previous functionallity and override only the * method we are interested in (in this case, the getActionURL() method). */ public MappingViewHandler(ViewHandler prevHandler) { this.prevHandler = prevHandler; } /** * Delegate control to the original ViewHandler */ public Locale calculateLocale(FacesContext context) { return prevHandler.calculateLocale(context); } /** * Delegate control to the original ViewHandler */ public String calculateRenderKitId(FacesContext context) { return prevHandler.calculateRenderKitId(context); } /** * Delegate control to the original ViewHandler */ public UIViewRoot createView(FacesContext context, String viewId) { return prevHandler.createView(context, viewId); } /** * This is the only method needed to be extended. First, we get the * normal URL form the original ViewHandler. Then we simply return * the same URL with the extension stripped of. */ public String getActionURL(FacesContext context, String viewId) { String origURL = prevHandler.getActionURL(context, viewId); int dotIdx = origURL.lastIndexOf("."); if (dotIdx > 0) { return origURL.substring(0,dotIdx); } else return origURL; } /** * Delegate control to the original ViewHandler */ public String getResourceURL(FacesContext context, String path) { return prevHandler.getResourceURL(context, path); } /** * Delegate control to the original ViewHandler */ public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException { prevHandler.renderView(context, viewToRender); } /** * Delegate control to the original ViewHandler */ public UIViewRoot restoreView(FacesContext context, String viewId) { return prevHandler.restoreView(context, viewId); } /** * Delegate control to the original ViewHandler */ public void writeState(FacesContext context) throws IOException { prevHandler.writeState(context); } }