O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required