FileDocCategorySizeDatePackage
SubscribeView.javaAPI DocExample3020Tue Jun 08 11:26:42 BST 2004com.mycompany.newsservice.views

SubscribeView

public class SubscribeView extends Object implements com.mycompany.jsf.pl.View
This class is an example of a pure Java view representation for a fictitious newsletter subscription service subscription interface, used by the example ClassViewHandler implementation.
author
Hans Bergsten, Gefion Software
version
1.0

Fields Summary
Constructors Summary
Methods Summary
public javax.faces.component.UIViewRootcreateView(javax.faces.context.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}");
        email.setValueBinding("value", emailAddr);
        grid.getChildren().add(email);

        UIOutput subsLabel = new UIOutput();
        subsLabel.setValue("Newsletters:");
        grid.getChildren().add(subsLabel);
        UISelectMany subs = new UISelectMany();
        subs.setRendererType("javax.faces.Checkbox");
        ValueBinding subIds = 
            application.createValueBinding("#{subscr.subscriptionIds}");
        subs.setValueBinding("value", subIds);
        UISelectItems sis = new UISelectItems();
        List choices = new ArrayList();
        choices.add(new SelectItem("1", "JSF News"));
        choices.add(new SelectItem("2", "IT Industry News"));
        choices.add(new SelectItem("3", "Company News"));
        sis.setValue(choices);
        subs.getChildren().add(sis);
        grid.getChildren().add(subs);
        form.getChildren().add(grid);

        UICommand command = new UICommand();
        command.setValue("Save");
        MethodBinding action = 
            application.createMethodBinding("#{subscrHandler.saveSubscriber}",
                null);
        command.setAction(action);
        form.getChildren().add(command);
        viewRoot.getChildren().add(form);

        return viewRoot;