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 View Class

Before we look at the custom ViewHandler, let’s look at a class that creates a view. The com.mycompany.newsservice.views.SubscribeView class creates a view that’s identical to the newsletter subscription example in Chapter 2:

package com.mycompany.newsservice.views; import javax.faces.application.Application; import javax.faces.component.UICommand; import javax.faces.component.UIForm; import javax.faces.component.UIInput; import javax.faces.component.UIOutput; import javax.faces.component.UIPanel; import javax.faces.component.UISelectItems; import javax.faces.component.UISelectMany; import javax.faces.component.UIViewRoot; import javax.faces.context.FacesContext; import javax.faces.model.SelectItem; import javax.faces.el.MethodBinding; import javax.faces.el.ValueBinding; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.mycompany.jsf.pl.View; public class SubscribeView implements View { public UIViewRoot createView(FacesContext context) { Application application = context.getApplication( ); UIViewRoot viewRoot = new UIViewRoot( ); UIForm form = new UIForm( ); viewRoot.getChildren( ).add(form); UIPanel grid = new UIPanel( ); grid.setRendererType("javax.faces.Grid"); grid.getAttributes( ).put("columns", "2"); UIOutput emailLabel = new UIOutput( ); emailLabel.setValue("Email Address:"); grid.getChildren( ).add(emailLabel); UIInput email = new UIInput( ); ValueBinding emailAddr = application.createValueBinding("#{subscr.emailAddr}"); ...

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