Developing the ViewHandler
Let’s move on to the custom ViewHandler
that
supports views represented by regular Java classes like the
SubscribeView
class. The class declaration and the
constructor look like this:
package com.mycompany.jsf.pl; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Map; import javax.faces.FactoryFinder; import javax.faces.application.StateManager; import javax.faces.application.StateManager.SerializedView; import javax.faces.application.ViewHandler; import javax.faces.component.UIComponent; import javax.faces.component.UIViewRoot; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.faces.context.ResponseWriter; import javax.faces.render.RenderKit; import javax.faces.render.RenderKitFactory; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import com.mycompany.newsservice.views.SubscribeView; public class ClassViewHandlerImpl extends ViewHandler { private static final String STATE_VAR = "com.mycompany.viewState"; protected ViewHandler origViewHandler; private Map views = new HashMap( ); public ClassViewHandlerImpl(ViewHandler origViewHandler) { this.origViewHandler = origViewHandler; }
The com.mycompany.jsf.pl.ClassViewHandlerImpl
extends the abstract ViewHandler
class. The
constructor takes an argument of type ViewHandler
Get JavaServer Faces now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.