click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r1061766 - in /click/trunk/click/examples/src/org/apache/click/examples: page/wizard/ service/
Date Fri, 21 Jan 2011 11:49:01 GMT
Author: sabob
Date: Fri Jan 21 11:49:01 2011
New Revision: 1061766

URL: http://svn.apache.org/viewvc?rev=1061766&view=rev
Log:
replaced stateful page example. CLK-715

Added:
    click/trunk/click/examples/src/org/apache/click/examples/page/wizard/WizardUils.java
Modified:
    click/trunk/click/examples/src/org/apache/click/examples/page/wizard/SelectPostCode.java
    click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step.java
    click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step1.java
    click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step2.java
    click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step3.htm
    click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step3.java
    click/trunk/click/examples/src/org/apache/click/examples/page/wizard/WizardPage.java
    click/trunk/click/examples/src/org/apache/click/examples/service/ClientService.java

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/wizard/SelectPostCode.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/wizard/SelectPostCode.java?rev=1061766&r1=1061765&r2=1061766&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/wizard/SelectPostCode.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/wizard/SelectPostCode.java Fri Jan 21 11:49:01 2011
@@ -1,102 +1,102 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.click.examples.page.wizard;
-
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import org.apache.click.Context;
-import org.apache.click.control.AbstractLink;
-import org.apache.click.control.Column;
-import org.apache.click.control.PageLink;
-import org.apache.click.control.Table;
-import org.apache.click.examples.domain.PostCode;
-import org.apache.click.examples.page.BorderPage;
-import org.apache.click.examples.service.PostCodeService;
-import org.apache.click.extras.control.LinkDecorator;
-import org.apache.click.util.HtmlStringBuffer;
-import org.springframework.stereotype.Component;
-
-/**
- * This Page provides a table to select the postal code from.
- *
- * It also acts as a fork in step 2, to show how one can navigate away from
- * a stateful page and then go back, with the components on the WizardPage still
- * populated with their old values.
- */
-@Component
-public class SelectPostCode extends BorderPage {
-
-    private static final long serialVersionUID = 1L;
-
-    /** Reference to the table. */
-    private Table table = new Table("table");
-
-    @Resource(name="postCodeService")
-    private PostCodeService postCodeService;
-
-    /**
-     * Default constructor.
-     */
-    public SelectPostCode() {
-        table.addColumn(new Column("postCode"));
-        table.addColumn(new Column("state"));
-        table.addColumn(new Column("locality"));
-        PageLink selectState = new PageLink("select", WizardPage.class);
-        Column action = new Column("action");
-        LinkDecorator decorator = new LinkDecorator(table, selectState, "postCode") {
-
-            private static final long serialVersionUID = 1L;
-
-            /**
-             * Override default implementation to send parameters
-             * address.postCode and address.state to the WizardPage.
-             */
-            @Override
-            protected void renderActionLink(HtmlStringBuffer buffer,
-                AbstractLink link, Context context, Object row, Object value) {
-                // Remove the default parameter name set for the value
-                link.setParameter(idProperty, null);
-
-                PostCode postCode = (PostCode) row;
-                // Add extra parameters for each row to the rendered action link
-                link.setParameter("address.postCode", postCode.getPostCode());
-                link.setParameter("address.state", postCode.getState());
-                super.renderActionLink(buffer, link, context, row, value);
-            }
-        };
-
-        action.setDecorator(decorator);
-        table.addColumn(action);
-
-        table.setClass(Table.CLASS_BLUE2);
-        addControl(table);
-    }
-
-    /**
-     * Override onRender to populate the table row data.
-     */
-    @Override
-    public void onRender() {
-        List<PostCode> states = postCodeService.getPostCodes();
-        table.setRowList(states);
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.page.wizard;
+
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.click.Context;
+import org.apache.click.control.AbstractLink;
+import org.apache.click.control.Column;
+import org.apache.click.control.PageLink;
+import org.apache.click.control.Table;
+import org.apache.click.examples.domain.PostCode;
+import org.apache.click.examples.page.BorderPage;
+import org.apache.click.examples.service.PostCodeService;
+import org.apache.click.extras.control.LinkDecorator;
+import org.apache.click.util.HtmlStringBuffer;
+import org.springframework.stereotype.Component;
+
+/**
+ * This Page provides a table to select the postal code from.
+ *
+ * It also acts as a fork in step 2, to show how one can navigate away from
+ * a stateful page and then go back, with the components on the WizardPage still
+ * populated with their old values.
+ */
+@Component
+public class SelectPostCode extends BorderPage {
+
+    private static final long serialVersionUID = 1L;
+
+    /** Reference to the table. */
+    private Table table = new Table("table");
+
+    @Resource(name="postCodeService")
+    private PostCodeService postCodeService;
+
+    /**
+     * Default constructor.
+     */
+    public SelectPostCode() {
+        table.addColumn(new Column("postCode"));
+        table.addColumn(new Column("state"));
+        table.addColumn(new Column("locality"));
+        PageLink selectState = new PageLink("select", WizardPage.class);
+        Column action = new Column("action");
+        LinkDecorator decorator = new LinkDecorator(table, selectState, "postCode") {
+
+            private static final long serialVersionUID = 1L;
+
+            /**
+             * Override default implementation to send parameters
+             * address.postCode and address.state to the WizardPage.
+             */
+            @Override
+            protected void renderActionLink(HtmlStringBuffer buffer,
+                AbstractLink link, Context context, Object row, Object value) {
+                // Remove the default parameter name set for the value
+                link.setParameter(idProperty, null);
+
+                PostCode postCode = (PostCode) row;
+                // Add extra parameters for each row to the rendered action link
+                link.setParameter("address.postCode", postCode.getPostCode());
+                link.setParameter("address.state", postCode.getState());
+                super.renderActionLink(buffer, link, context, row, value);
+            }
+        };
+
+        action.setDecorator(decorator);
+        table.addColumn(action);
+
+        table.setClass(Table.CLASS_BLUE2);
+        addControl(table);
+    }
+
+    /**
+     * Override onRender to populate the table row data.
+     */
+    @Override
+    public void onRender() {
+        List<PostCode> states = postCodeService.getPostCodes();
+        table.setRowList(states);
+    }
+
+}

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step.java?rev=1061766&r1=1061765&r2=1061766&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step.java Fri Jan 21 11:49:01 2011
@@ -1,296 +1,263 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.click.examples.page.wizard;
-
-import org.apache.click.examples.control.SimplePanel;
-import org.apache.click.ActionListener;
-import org.apache.click.Control;
-import org.apache.click.control.Button;
-import org.apache.click.control.Form;
-import org.apache.click.control.Submit;
-import org.apache.click.examples.control.cayenne.NestedCayenneForm;
-import org.apache.click.examples.domain.Client;
-import org.apache.click.extras.cayenne.CayenneForm;
-import org.apache.commons.lang.ClassUtils;
-
-/**
- * Provides common functionality for each step in the wizard.
- */
-public abstract class Step extends SimplePanel {
-
-    private static final long serialVersionUID = 1L;
-
-    // Variables --------------------------------------------------------------
-
-    /** Reference to the form. */
-    private CayenneForm form = new NestedCayenneForm("form"
-        + ClassUtils.getShortClassName(getClass()), Client.class);
-
-    /** Reference to the wizard page. */
-    private WizardPage wizardPage;
-
-    /** Reference to the step description. */
-    private String description;
-
-    /** Reference to the next button. */
-    private Button next;
-
-    /** Reference to the previous button. */
-    private Button previous;
-
-    /** Reference to the finish button. */
-    private Button finish;
-
-    /** Reference to the cancel button. */
-    private Button cancel;
-
-    // Constructor ------------------------------------------------------------
-
-    /**
-     * Constructs a Step for the specified name and page.
-     *
-     * @param name the step name
-     * @param label the step label
-     * @param description the step description
-     * @param page the wizard page
-     */
-    public Step(String name, String label, String description, WizardPage page) {
-        super(name);
-        setWizardPage(page);
-        setLabel(label);
-        setDescription(description);
-    }
-
-    // Public Properties ------------------------------------------------------
-
-    /**
-     * Return the Step form instance.
-     *
-     * @return the Step form instance
-     */
-    public CayenneForm getForm() {
-        return form;
-    }
-
-    /**
-     * Set the form instance.
-     *
-     * @param form the form for this Step
-     */
-    public void setForm(CayenneForm form) {
-        this.form = form;
-    }
-
-    /**
-     * Return the Step WizardPage instance.
-     *
-     * @return the WizardPage instance
-     */
-    public WizardPage getWizardPage() {
-        return wizardPage;
-    }
-
-    /**
-     * Set the WizardPage instance.
-     *
-     * @param wizardPage the WizardPage instance for this Step
-     */
-    public void setWizardPage(WizardPage wizardPage) {
-        this.wizardPage = wizardPage;
-    }
-
-    /**
-     * Return the Step description.
-     *
-     * @return the Step description
-     */
-    public String getDescription() {
-        return description;
-    }
-
-    /**
-     * Set the Step visual description.
-     *
-     * @param description the visual description
-     */
-    public void setDescription(String description) {
-        this.description = description;
-    }
-
-    /**
-     * Return the Client instance.
-     *
-     * @return the Client instance
-     */
-    public Client getClient() {
-        // form.getDataObject ensures that latest field values are copied to
-        // domain object
-        return (Client) getForm().getDataObject();
-    }
-
-    /**
-     * Set the Client instance.
-     *
-     * @param client the client for this Step
-     */
-    public void setClient(Client client) {
-        getForm().setDataObject(client);
-    }
-
-    /**
-     * Return the button representing the next action.
-     *
-     * @return the button representing the next action
-     */
-    public Button getNextButton() {
-        return next;
-    }
-
-    /**
-     * Return the button representing the previous action.
-     *
-     * @return the button representing the previous action
-     */
-    public Button getPreviousButton() {
-        return previous;
-    }
-
-    /**
-     * Return the button representing the next action.
-     *
-     * @return the button representing the next action
-     */
-    public Button getFinishButton() {
-        return finish;
-    }
-
-    /**
-     * Return the button representing the cancel action.
-     *
-     * @return the button representing the cancel action
-     */
-    public Button getCancelButton() {
-        return cancel;
-    }
-
-    // Public Methods ---------------------------------------------------------
-
-    /**
-     * The onNext action. Subclasses can override this method to implement
-     * custom logic.
-     *
-     * @return true if Page processing should continue, false otherwise
-     */
-    public boolean onNext() {
-        return true;
-    }
-
-    /**
-     * The onPrevious action. Subclasses can override this method to implement
-     * custom logic.
-     *
-     * @return true if Page processing should continue, false otherwise
-     */
-    public boolean onPrevious() {
-        return true;
-    }
-
-    /**
-     * The onFinish action. Subclasses can override this method to implement
-     * custom logic.
-     *
-     * @return true if Page processing should continue, false otherwise
-     */
-    public boolean onFinish() {
-        return true;
-    }
-
-    /**
-     * The onCancel action. Subclasses can override this method to implement
-     * custom logic.
-     *
-     * @return true if Page processing should continue, false otherwise
-     */
-    public boolean onCancel() {
-        // Set a flash cancel message
-        getContext().setFlashAttribute("message", "You have cancelled the "
-            + "client creation process.");
-
-        // Set page state to stateless which removes the page from
-        // the session
-        getWizardPage().setStateful(false);
-        getWizardPage().setRedirect(WizardPage.class);
-        return false;
-    }
-
-    /**
-     * Setup and initializes the Step. This method must be called before
-     * the Step can be used.
-     */
-    @SuppressWarnings("serial")
-    public final void init() {
-        getForm().setButtonAlign(Form.ALIGN_RIGHT);
-        getForm().setErrorsPosition(Form.POSITION_MIDDLE);
-
-        previous = new Submit("previous");
-        previous.setLabel("< Previous");
-        getPreviousButton().setActionListener(new ActionListener() {
-            public boolean onAction(Control source) {
-                return onPrevious();
-            }
-        });
-        form.add(previous);
-        if (!getWizardPage().hasPreviousStep(this)) {
-            previous.setDisabled(true);
-        }
-
-        next = new Submit("next");
-        next.setLabel("Next >");
-        getNextButton().setActionListener(new ActionListener() {
-            public boolean onAction(Control source) {
-                return onNext();
-            }
-        });
-        form.add(next);
-        if (!getWizardPage().hasNextStep(this)) {
-            next.setDisabled(true);
-        }
-
-        finish = new Submit("Finish");
-        getFinishButton().setActionListener(new ActionListener() {
-            public boolean onAction(Control source) {
-                return onFinish();
-            }
-        });
-        form.add(finish);
-        if (!getWizardPage().isLastStep(this)) {
-            finish.setDisabled(true);
-        }
-
-        cancel = new Submit("Cancel");
-        getCancelButton().setActionListener(new ActionListener() {
-            public boolean onAction(Control source) {
-                return onCancel();
-            }
-        });
-        form.add(cancel);
-
-        add(form);
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.page.wizard;
+
+import org.apache.click.examples.control.SimplePanel;
+import org.apache.click.ActionListener;
+import org.apache.click.Control;
+import org.apache.click.control.Button;
+import org.apache.click.control.Form;
+import org.apache.click.control.Submit;
+
+/**
+ * Provides common functionality for each step in the wizard.
+ */
+public abstract class Step extends SimplePanel {
+
+    private static final long serialVersionUID = 1L;
+
+    // Variables --------------------------------------------------------------
+
+    /** Reference to the form. */
+    private Form form = new Form("form");
+
+    /** Reference to the wizard page. */
+    private WizardPage wizardPage;
+
+    /** Reference to the step description. */
+    private String description;
+
+    /** Reference to the next button. */
+    private Button next;
+
+    /** Reference to the previous button. */
+    private Button previous;
+
+    /** Reference to the finish button. */
+    private Button finish;
+
+    /** Reference to the cancel button. */
+    private Button cancel;
+
+    // Constructor ------------------------------------------------------------
+
+    /**
+     * Constructs a Step for the specified name and page.
+     *
+     * @param name the step name
+     * @param label the step label
+     * @param description the step description
+     * @param page the wizard page
+     */
+    public Step(String name, String label, String description, WizardPage page) {
+        super(name);
+        setWizardPage(page);
+        setLabel(label);
+        setDescription(description);
+    }
+
+    // Public Properties ------------------------------------------------------
+
+    /**
+     * Return the Step form instance.
+     *
+     * @return the Step form instance
+     */
+    public Form getForm() {
+        return form;
+    }
+
+
+    /**
+     * Return the Step WizardPage instance.
+     *
+     * @return the WizardPage instance
+     */
+    public WizardPage getWizardPage() {
+        return wizardPage;
+    }
+
+    /**
+     * Set the WizardPage instance.
+     *
+     * @param wizardPage the WizardPage instance for this Step
+     */
+    public void setWizardPage(WizardPage wizardPage) {
+        this.wizardPage = wizardPage;
+    }
+
+    /**
+     * Return the Step description.
+     *
+     * @return the Step description
+     */
+    public String getDescription() {
+        return description;
+    }
+
+    /**
+     * Set the Step visual description.
+     *
+     * @param description the visual description
+     */
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    /**
+     * Return the button representing the next action.
+     *
+     * @return the button representing the next action
+     */
+    public Button getNextButton() {
+        return next;
+    }
+
+    /**
+     * Return the button representing the previous action.
+     *
+     * @return the button representing the previous action
+     */
+    public Button getPreviousButton() {
+        return previous;
+    }
+
+    /**
+     * Return the button representing the next action.
+     *
+     * @return the button representing the next action
+     */
+    public Button getFinishButton() {
+        return finish;
+    }
+
+    /**
+     * Return the button representing the cancel action.
+     *
+     * @return the button representing the cancel action
+     */
+    public Button getCancelButton() {
+        return cancel;
+    }
+
+    // Public Methods ---------------------------------------------------------
+
+    /**
+     * The onNext action. Subclasses can override this method to implement
+     * custom logic.
+     *
+     * @return true if Page processing should continue, false otherwise
+     */
+    public boolean onNext() {
+        return true;
+    }
+
+    /**
+     * The onPrevious action. Subclasses can override this method to implement
+     * custom logic.
+     *
+     * @return true if Page processing should continue, false otherwise
+     */
+    public boolean onPrevious() {
+        return true;
+    }
+
+    /**
+     * The onFinish action. Subclasses can override this method to implement
+     * custom logic.
+     *
+     * @return true if Page processing should continue, false otherwise
+     */
+    public boolean onFinish() {
+        return true;
+    }
+
+    /**
+     * The onCancel action. Subclasses can override this method to implement
+     * custom logic.
+     *
+     * @return true if Page processing should continue, false otherwise
+     */
+    public boolean onCancel() {
+        // Set a flash cancel message
+        getContext().setFlashAttribute("message", "You have cancelled the "
+            + "client creation process.");
+
+        // Set page state to stateless which removes the page from
+        // the session
+        getWizardPage().setRedirect(WizardPage.class);
+        return false;
+    }
+
+    /**
+     * Setup and initializes the Step. This method must be called before
+     * the Step can be used.
+     */
+    @SuppressWarnings("serial")
+    public final void init() {
+        Form localForm = getForm();
+        localForm.setButtonAlign(Form.ALIGN_RIGHT);
+        localForm.setErrorsPosition(Form.POSITION_MIDDLE);
+
+        previous = new Submit("previous");
+        previous.setLabel("< Previous");
+        getPreviousButton().setActionListener(new ActionListener() {
+            public boolean onAction(Control source) {
+                return onPrevious();
+            }
+        });
+        localForm.add(previous);
+        if (!getWizardPage().hasPreviousStep()) {
+            previous.setDisabled(true);
+        }
+
+        next = new Submit("next");
+        next.setLabel("Next >");
+        getNextButton().setActionListener(new ActionListener() {
+            public boolean onAction(Control source) {
+                return onNext();
+            }
+        });
+        localForm.add(next);
+        if (!getWizardPage().hasNextStep()) {
+            next.setDisabled(true);
+        }
+
+        finish = new Submit("Finish");
+        getFinishButton().setActionListener(new ActionListener() {
+            public boolean onAction(Control source) {
+                return onFinish();
+            }
+        });
+        localForm.add(finish);
+        if (!getWizardPage().isLastStep()) {
+            finish.setDisabled(true);
+        }
+
+        cancel = new Submit("Cancel");
+        getCancelButton().setActionListener(new ActionListener() {
+            public boolean onAction(Control source) {
+                return onCancel();
+            }
+        });
+        localForm.add(cancel);
+
+        add(localForm);
+    }
+}

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step1.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step1.java?rev=1061766&r1=1061765&r2=1061766&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step1.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step1.java Fri Jan 21 11:49:01 2011
@@ -1,76 +1,127 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.click.examples.page.wizard;
-
-import org.apache.click.control.TextField;
-import org.apache.click.extras.cayenne.QuerySelect;
-import org.apache.click.extras.control.DateField;
-import org.apache.click.extras.control.EmailField;
-
-/**
- * The first step in the 3 step process is to capture the Client details.
- * <p/>
- * Note this Panel has no associated template.
- */
-public class Step1 extends Step {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * Construct Step1 with the specified name, label, description and page.
-     *
-     * @param name the step name
-     * @param label the step label
-     * @param description the step description
-     * @param page the wizard page
-     */
-    public Step1(String name, String label, String description, WizardPage page) {
-        super(name, label, description, page);
-
-        QuerySelect querySelect = new QuerySelect("title", true);
-        querySelect.setQueryValueLabel("titles", "value", "label");
-        getForm().add(querySelect);
-
-        getForm().add(new TextField("firstName"));
-        getForm().add(new TextField("lastName"));
-        getForm().add(new DateField("dateJoined"));
-        getForm().add(new EmailField("email"));
-    }
-
-    /**
-     * The onNext action of Step1 sets the Page to stateful, checks if the form
-     * is valid, moves to the next step in the process and passes the client to
-     * the next step.
-     *
-     * @return true if page processing should continue or not
-     */
-    @Override
-    public boolean onNext() {
-        // Set the page to stateful so the same Page is available throughout the
-        // Wizard steps
-        getWizardPage().setStateful(true);
-
-        if (getForm().isValid()) {
-            // Pass the client to Panel2
-            getWizardPage().next();
-            getWizardPage().getCurrentStep().setClient(getClient());
-        }
-        return true;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.page.wizard;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.click.control.Option;
+import org.apache.click.control.Select;
+import org.apache.click.control.TextField;
+import org.apache.click.dataprovider.DataProvider;
+import org.apache.click.examples.domain.Address;
+import org.apache.click.examples.domain.Client;
+import org.apache.click.examples.domain.SystemCode;
+import org.apache.click.examples.service.ClientService;
+import org.apache.click.extras.control.DateField;
+import org.apache.click.extras.control.EmailField;
+
+/**
+ * The first step in the 3 step process is to capture the Client details.
+ * <p/>
+ * Note this Panel has no associated template.
+ */
+public class Step1 extends Step {
+
+    private static final long serialVersionUID = 1L;
+
+    /** The client domain object created through the wizard. */
+    private Client client;
+
+    private ClientService clientService;
+
+    /**
+     * Construct Step1 with the specified name, label, description and page.
+     *
+     * @param name the step name
+     * @param label the step label
+     * @param description the step description
+     * @param page the wizard page
+     */
+    public Step1(String name, String label, String description, WizardPage page) {
+        super(name, label, description, page);
+
+        Select titleSelect = createTitleSelect();
+        getForm().add(titleSelect);
+
+        getForm().add(new TextField("firstName", true));
+        getForm().add(new TextField("lastName", true));
+        getForm().add(new DateField("dateJoined", true));
+        getForm().add(new EmailField("email"));
+
+        client = WizardUils.getClientFromSession();
+        if (client != null) {
+            getForm().copyFrom(client);
+        }
+    }
+
+    /**
+     * The onNext action of Step1 sets the Page to stateful, checks if the form
+     * is valid, moves to the next step in the process and passes the client to
+     * the next step.
+     *
+     * @return true if page processing should continue or not
+     */
+    @Override
+    public boolean onNext() {
+        if (getForm().isValid()) {
+
+            // Only create client if no client was loaded from the session in this
+            // Step's constructor. This allows the user to freely navigate backwards
+            // and forwards through the wizard without overwriting a previous Client
+            // instance
+            if (client == null) {
+                ClientService service = getClientService();
+                client = service.createNewClient();
+                Address address = service.createNewAddress();
+                client.setAddress(address);
+            }
+            getForm().copyTo(client);
+            WizardUils.saveClientInSession(client);
+
+            getWizardPage().next();
+        }
+        return true;
+    }
+
+    public ClientService getClientService() {
+        if (clientService == null) {
+            clientService = new ClientService();
+        }
+        return clientService;
+    }
+
+    private Select createTitleSelect() {
+        Select titleSelect = new Select("title", true);
+
+        titleSelect.setDefaultOption(Option.EMPTY_OPTION);
+
+        titleSelect.setDataProvider(new DataProvider() {
+
+            public List<Option> getData() {
+                List<Option> options = new ArrayList<Option>();
+                List<SystemCode> titles = getClientService().getTitles();
+                for (SystemCode title : titles) {
+                    options.add(new Option(title.getValue(), title.getLabel()));
+                }
+                return options;
+            }
+        });
+        return titleSelect;
+    }
+}

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step2.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step2.java?rev=1061766&r1=1061765&r2=1061766&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step2.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step2.java Fri Jan 21 11:49:01 2011
@@ -1,144 +1,158 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.click.examples.page.wizard;
-
-import org.apache.click.control.AbstractContainer;
-import org.apache.click.control.PageLink;
-import org.apache.click.control.TextField;
-import org.apache.click.examples.control.cayenne.CayenneIntegerField;
-import org.apache.click.extras.cayenne.QuerySelect;
-import org.apache.click.extras.control.IntegerField;
-
-/**
- * The second step in the 3 step process is to capture the Client address.
- * <p/>
- * Note this Panel has no associated template.
- */
-public class Step2 extends Step {
-
-    private static final long serialVersionUID = 1L;
-
-    /** Reference to the postCode field. */
-    private IntegerField postCodeField;
-
-    /** Reference to the state field. */
-    private QuerySelect stateSelect;
-
-    /**
-     * Construct Step2 with the specified name, label, description and page.
-     *
-     * @param name the step name
-     * @param label the step label
-     * @param description the step description
-     * @param page the wizard page
-     */
-    public Step2(String name, String label, String description, WizardPage page) {
-        super(name, label, description, page);
-
-        // PageLink to page where post codes can be looked up
-        final PageLink postCodeLookup = new PageLink("postCodePage", "Lookup Post Code", SelectPostCode.class);
-
-        // We want to right align the postCodeLookup link, however fields must
-        // be left aligned. In order to do this we wrap postCodeLookupPage inside
-        // a div (block level element) and set its contents to be right aligned.
-        Div postCodeLookupWrapper = new Div();
-        postCodeLookupWrapper.add(postCodeLookup);
-        postCodeLookupWrapper.setStyle("text-align", "right");
-
-        getForm().add(postCodeLookupWrapper);
-
-        getForm().add(new TextField("address.line1", "Line One"));
-        getForm().add(new TextField("address.line2", "Line Two"));
-        getForm().add(new TextField("address.suburb", "Suburb"));
-
-        stateSelect = new QuerySelect("address.state", "State", true);
-
-        stateSelect.setQueryValueLabel("states", "value", "label");
-        getForm().add(stateSelect);
-        postCodeField = new CayenneIntegerField("address.postCode", "Post Code");
-        postCodeField.setMaxLength(5);
-        postCodeField.setSize(5);
-        getForm().add(postCodeField);
-    }
-
-    /**
-     * Step2 links to a lookup table for populating the post code and state values.
-     *
-     * The onInit phase is overridden to check if the post code and state values
-     * are passed in from the lookup table.
-     */
-    @Override
-    public void onInit() {
-        // Invoke default onInit implementation
-        super.onInit();
-
-        // Check if postCode is passed to this Page from SelectPostCode page
-        String postCodeValue = getContext().getRequestParameter(postCodeField.getName());
-        if (postCodeValue != null) {
-            postCodeField.setValue(postCodeValue);
-        }
-        // Check if state is passed to this Page from SelectPostCode page
-        String stateValue = getContext().getRequestParameter(stateSelect.getName());
-        if (stateValue != null) {
-            stateSelect.setValue(stateValue);
-        }
-    }
-
-    /**
-     * The onNext action of Step2 checks if the form is valid, moves to the
-     * next step in the process and passes the client to the next step.
-     *
-     * @return true if page processing should continue or not
-     */
-    @Override
-    public boolean onNext() {
-        if (getForm().isValid()) {
-            // Pass client to next Step
-            getWizardPage().next();
-            getWizardPage().getCurrentStep().setClient(getClient());
-        }
-        return true;
-    }
-
-    /**
-     * The onPrevious action of Step2 moves to the previous step in the process
-     * and clears and form errors.
-     *
-     * @return true if page processing should continue or not
-     */
-    @Override
-    public boolean onPrevious() {
-        getWizardPage().previous();
-        getForm().clearErrors();
-        return false;
-    }
-
-    /**
-     * Represents a Div HTML element.
-     */
-    class Div extends AbstractContainer {
-        private static final long serialVersionUID = 1L;
-
-        @Override
-        public String getTag() {
-            return "div";
-        }
-    }
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.page.wizard;
+
+import org.apache.click.control.AbstractContainer;
+import org.apache.click.control.PageLink;
+import org.apache.click.control.TextField;
+import org.apache.click.examples.domain.Client;
+import org.apache.click.extras.cayenne.QuerySelect;
+import org.apache.click.extras.control.IntegerField;
+
+/**
+ * The second step in the 3 step process is to capture the Client address.
+ * <p/>
+ * Note this Panel has no associated template.
+ */
+public class Step2 extends Step {
+
+    private static final long serialVersionUID = 1L;
+
+    /** Reference to the postCode field. */
+    private IntegerField postCodeField;
+
+    /** Reference to the state field. */
+    private QuerySelect stateSelect;
+
+    /** The client domain object created through the wizard. */
+    private Client client;
+
+    /**
+     * Construct Step2 with the specified name, label, description and page.
+     *
+     * @param name the step name
+     * @param label the step label
+     * @param description the step description
+     * @param page the wizard page
+     */
+    public Step2(String name, String label, String description, WizardPage page) {
+        super(name, label, description, page);
+
+        // PageLink to page where post codes can be looked up
+        final PageLink postCodeLookup = new PageLink("postCodePage", "Lookup Post Code", SelectPostCode.class);
+
+        // We want to right align the postCodeLookup link, however fields must
+        // be left aligned. In order to do this we wrap postCodeLookupPage inside
+        // a div (block level element) and set its contents to be right aligned.
+        Div postCodeLookupWrapper = new Div();
+        postCodeLookupWrapper.add(postCodeLookup);
+        postCodeLookupWrapper.setStyle("text-align", "right");
+
+        getForm().add(postCodeLookupWrapper);
+
+        getForm().add(new TextField("address.line1", "Line One", true));
+        getForm().add(new TextField("address.line2", "Line Two"));
+        getForm().add(new TextField("address.suburb", "Suburb", true));
+
+        stateSelect = new QuerySelect("address.state", "State", true);
+
+        stateSelect.setQueryValueLabel("states", "value", "label");
+        getForm().add(stateSelect);
+        postCodeField = new IntegerField("address.postCode", "Post Code");
+        postCodeField.setRequired(true);
+        postCodeField.setMaxLength(5);
+        postCodeField.setSize(5);
+        getForm().add(postCodeField);
+
+        client = WizardUils.getClientFromSession();
+        if (client != null) {
+            getForm().copyFrom(client);
+        }
+    }
+
+    /**
+     * Step2 links to a lookup table for populating the post code and state values.
+     *
+     * The onInit phase is overridden to check if the post code and state values
+     * are passed in from the lookup table.
+     */
+    @Override
+    public void onInit() {
+        // Invoke default onInit implementation
+        super.onInit();
+
+        // Check if postCode is passed to this Page from SelectPostCode page
+        String postCodeValue = getContext().getRequestParameter(postCodeField.getName());
+        if (postCodeValue != null) {
+            postCodeField.setValue(postCodeValue);
+        }
+        // Check if state is passed to this Page from SelectPostCode page
+        String stateValue = getContext().getRequestParameter(stateSelect.getName());
+        if (stateValue != null) {
+            stateSelect.setValue(stateValue);
+        }
+    }
+
+    /**
+     * The onNext action of Step2 checks if the form is valid, moves to the
+     * next step in the process and passes the client to the next step.
+     *
+     * @return true if page processing should continue or not
+     */
+    @Override
+    public boolean onNext() {
+        if (getForm().isValid()) {
+
+            getForm().copyTo(client);
+            WizardUils.saveClientInSession(client);
+
+            // Pass client to next Step
+            getWizardPage().next();
+        }
+        return true;
+    }
+
+    /**
+     * The onPrevious action of Step2 moves to the previous step in the process
+     * and clears and form errors.
+     *
+     * @return true if page processing should continue or not
+     */
+    @Override
+    public boolean onPrevious() {
+        getWizardPage().previous();
+        getForm().clearErrors();
+        getForm().copyTo(client);
+        WizardUils.saveClientInSession(client);
+        return false;
+    }
+
+    /**
+     * Represents a Div HTML element.
+     */
+    class Div extends AbstractContainer {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public String getTag() {
+            return "div";
+        }
+    }
+}
+

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step3.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step3.htm?rev=1061766&r1=1061765&r2=1061766&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step3.htm (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step3.htm Fri Jan 21 11:49:01 2011
@@ -70,4 +70,4 @@
   </table>
 #end
 
-$formStep3
+$form

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step3.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step3.java?rev=1061766&r1=1061765&r2=1061766&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step3.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/wizard/Step3.java Fri Jan 21 11:49:01 2011
@@ -1,101 +1,109 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.click.examples.page.wizard;
-
-/**
- * This step asks for confirmation on the client information added through the
- * wizard. If user confirms, the new client is inserted into the database,
- * if user cancels the wizard is ended and user is redirected back to the first
- * step.
- * <p/>
- * Step3 uses a Velocity template (Step3.htm) to render client
- * information.
- */
-public class Step3 extends Step {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * Construct Step3 with the specified name, label, description and page.
-     *
-     * @param name the step name
-     * @param label the step label
-     * @param description the step description
-     * @param page the wizard
-     */
-    public Step3(String name, String label, String description, WizardPage page) {
-        super(name, label, description, page);
-    }
-
-    /**
-     * The onFinish action of Step3 checks if the form is valid, saves the
-     * client and address in the database, sets up a success message, and
-     * sets the page back to stateless.
-     *
-     * @return true if page processing should continue or not
-     */
-    @Override
-    public boolean onFinish() {
-        if (getForm().isValid()) {
-
-            // Store client and associated address in the database
-            getForm().saveChanges();
-
-            // Set a flash success message
-            getContext().setFlashAttribute("message", "The client "
-                + getClient().getName() + " was successfully created.");
-
-            // Set page state to stateless which removes the page from
-            // the session
-            getWizardPage().setStateful(false);
-
-            // Redirect to wizard page to start another process
-            getWizardPage().setRedirect(WizardPage.class);
-        }
-        return true;
-    }
-
-    /**
-     * The onPrevious action of Step3 moves to the previous step in the process
-     * and clears and form errors.
-     *
-     * @return true if page processing should continue or not
-     */
-    @Override
-    public boolean onPrevious() {
-        getWizardPage().previous();
-        getForm().clearValues();
-        return false;
-    }
-
-    /**
-     * Override onRender phase to add the client instance to the Template
-     * model for rendering.
-     */
-    @Override
-    public void onRender() {
-        // Invoke default onInit implementation
-        super.onRender();
-
-        // Add client to model for displaying confirmation message
-        if (!getModel().containsKey("client")) {
-            addModel("client", getClient());
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.page.wizard;
+
+import org.apache.click.examples.domain.Client;
+import org.apache.click.examples.service.ClientService;
+
+/**
+ * This step asks for confirmation on the client information added through the
+ * wizard. If user confirms, the new client is inserted into the database,
+ * if user cancels the wizard is ended and user is redirected back to the first
+ * step.
+ * <p/>
+ * Step3 uses a Velocity template (Step3.htm) to render client
+ * information.
+ */
+public class Step3 extends Step {
+
+    private static final long serialVersionUID = 1L;
+
+    /** The client domain object created through the wizard. */
+    private Client client;
+
+    /**
+     * Construct Step3 with the specified name, label, description and page.
+     *
+     * @param name the step name
+     * @param label the step label
+     * @param description the step description
+     * @param page the wizard
+     */
+    public Step3(String name, String label, String description, WizardPage page) {
+        super(name, label, description, page);
+        client = WizardUils.getClientFromSession();
+    }
+
+    /**
+     * The onFinish action of Step3 checks if the form is valid, saves the
+     * client and address in the database, sets up a success message, and
+     * sets the page back to stateless.
+     *
+     * @return true if page processing should continue or not
+     */
+    @Override
+    public boolean onFinish() {
+        if (getForm().isValid()) {
+
+            // Store client and associated address in the database
+            ClientService service = new ClientService();
+            service.saveClient(client);
+
+            // Set a flash success message
+            getContext().setFlashAttribute("message", "The client "
+                + client.getName() + " was successfully created.");
+
+            // Remove client from session
+            WizardUils.removeClientFromSession();
+
+            // Set Step index back to 0
+            getWizardPage().setCurrentStepIndex(0);
+
+            // Redirect to wizard page to start another process
+            getWizardPage().setRedirect(WizardPage.class);
+        }
+        return true;
+    }
+
+    /**
+     * The onPrevious action of Step3 moves to the previous step in the process
+     * and clears and form errors.
+     *
+     * @return true if page processing should continue or not
+     */
+    @Override
+    public boolean onPrevious() {
+        getWizardPage().previous();
+        getForm().clearValues();
+        return false;
+    }
+
+    /**
+     * Override onRender phase to add the client instance to the Template
+     * model for rendering.
+     */
+    @Override
+    public void onRender() {
+        // Invoke default onInit implementation
+        super.onRender();
+
+        // Add client to model for displaying confirmation message
+        addModel("client", client);
+    }
+}

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/wizard/WizardPage.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/wizard/WizardPage.java?rev=1061766&r1=1061765&r2=1061766&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/wizard/WizardPage.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/wizard/WizardPage.java Fri Jan 21 11:49:01 2011
@@ -1,185 +1,209 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.click.examples.page.wizard;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import org.apache.click.element.CssImport;
-import org.apache.click.examples.page.BorderPage;
-import org.apache.click.util.HtmlStringBuffer;
-
-/**
- * This Page manages steps in a wizard process.
- */
-public class WizardPage extends BorderPage {
-
-    private static final long serialVersionUID = 1L;
-
-    /** Current step in the process. */
-    private Step currentStep;
-
-    /** List of all steps. */
-    private List<Step> steps = new ArrayList<Step>();
-
-    // Constructor ------------------------------------------------------------
-
-    /**
-     * Default constructor.
-     */
-    public WizardPage() {
-        steps.add(new Step1("step", "Client", "Step 1", this));
-        steps.add(new Step2("step", "Address", "Step 2", this));
-        steps.add(new Step3("step", "Confirmation", "Step 3", this));
-
-        // Set first step as current
-        setCurrentStep(steps.get(0));
-
-        // Initialize all the steps
-        Iterator it = steps.iterator();
-        while(it.hasNext()) {
-            Step step = (Step) it.next();
-            step.init();
-        }
-    }
-
-    // Public Methods ---------------------------------------------------------
-
-    /**
-     * Return the current step.
-     *
-     * @return the current step
-     */
-    public Step getCurrentStep() {
-        return currentStep;
-    }
-
-    /**
-     * Sets the current Step to the specified Step.
-     *
-     * @param step the new step to set
-     */
-    public void setCurrentStep(Step step) {
-        if (this.currentStep != null) {
-            // Remove the current step from the page list of controls
-            removeControl(this.currentStep);
-            getModel().remove("heading");
-        }
-        this.currentStep = step;
-        // Add the new step to the page list of controls
-        addControl(step);
-        addModel("heading", getHeading());
-    }
-
-    /**
-     * Return true if there is another step before the specified step.
-     *
-     * @param step the step to check against
-     * @return true if there is another step before the specified step
-     */
-    public boolean hasPreviousStep(Step step) {
-        return steps.indexOf(step) > 0;
-    }
-
-    /**
-     * Return true if there is another step after the specified step.
-     *
-     * @param step the step to check against
-     * @return true if there is another step after the specified step
-     */
-    public boolean hasNextStep(Step step) {
-        return !isLastStep(step);
-    }
-
-    /**
-     * Return true if the specified step is the last step in the process.
-     *
-     * @param step the step to check against
-     * @return true if the specified step is the last step in the process
-     */
-    public boolean isLastStep(Step step) {
-        int numberOfSteps = steps.size();
-        int currentStepIndex = steps.indexOf(step);
-
-        // currentStepIndex is a zero based index. Add 1 when comparing to
-        // numberOfSteps
-        return (numberOfSteps == currentStepIndex + 1);
-    }
-
-    /**
-     * Goto previous step.
-     */
-    public void previous() {
-        int currentIndex = steps.indexOf(getCurrentStep());
-        if (currentIndex > 0) {
-            setCurrentStep(steps.get(currentIndex - 1));
-        }
-    }
-
-    /**
-     * Goto next step.
-     */
-    public void next() {
-        int currentIndex = steps.indexOf(getCurrentStep());
-        if (currentIndex < steps.size() - 1) {
-            setCurrentStep(steps.get(currentIndex + 1));
-        }
-    }
-
-    /**
-     * Return the page stylesheet: wizard.css.
-     *
-     * @return the page stylesheet
-     */
-    @Override
-    public List getHeadElements() {
-        if (headElements == null) {
-            headElements = super.getHeadElements();
-            headElements.add(new CssImport("/wizard/wizard.css"));
-        }
-        return headElements;
-    }
-
-    // Private Methods --------------------------------------------------------
-
-    /**
-     * Return an HTML representation of the wizard steps as an Html List <ul>.
-     * The current step is assigned a special CSS class so it can be highlighted
-     * through CSS.
-     */
-    private String getHeading() {
-        HtmlStringBuffer buffer = new HtmlStringBuffer();
-        buffer.append("<ul id=\"steps\">");
-        for (Step step : steps) {
-            buffer.elementStart("li");
-            if (step == currentStep) {
-                buffer.appendAttribute("class", "current");
-            }
-            buffer.closeTag();
-            buffer.append(step.getDescription());
-            buffer.elementStart("span");
-            buffer.closeTag();
-            buffer.append(step.getLabel());
-            buffer.elementEnd("span");
-            buffer.elementEnd("li");
-        }
-        buffer.append("</ul>");
-        return buffer.toString();
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.page.wizard;
+
+import java.util.List;
+import org.apache.click.element.CssImport;
+import org.apache.click.examples.page.BorderPage;
+import org.apache.click.util.HtmlStringBuffer;
+
+/**
+ * This Page manages steps in a wizard process.
+ */
+public class WizardPage extends BorderPage {
+
+    private static final long serialVersionUID = 1L;
+
+    /** Current step in the process. */
+    private Step currentStep;
+
+    public static final String STEP1_DESC = "Client";
+    public static final String STEP2_DESC = "Address";
+    public static final String STEP3_DESC = "Confirmation";
+
+    public static final String STEP1_LABEL = "Step 1";
+    public static final String STEP2_LABEL = "Step 2";
+    public static final String STEP3_LABEL = "Step 3";
+
+    public String[] stepDescriptions = {STEP1_DESC, STEP2_DESC, STEP3_DESC};
+    public String[] stepLabels = {STEP1_LABEL, STEP2_LABEL, STEP3_LABEL};
+
+    private int numberOfSteps = stepDescriptions.length;
+
+    private int currentStepIndex = 0;
+
+    // Constructor ------------------------------------------------------------
+
+    /**
+     * Default constructor.
+     */
+    public WizardPage() {
+        // Lookup step ID; defaults to "0"
+        int stepId = WizardUils.restoreActiveStepIndex();
+        setCurrentStepIndex(stepId);
+
+        //setCurrentStep(steps.get(stepIndex));
+
+        // Initialize all the steps
+        /*
+        Iterator it = steps.iterator();
+        while(it.hasNext()) {
+            Step step = (Step) it.next();
+            step.init();
+        }
+         *
+         */
+    }
+
+    // Public Methods ---------------------------------------------------------
+
+    /**
+     * Return the current step.
+     *
+     * @return the current step
+     */
+    public Step getCurrentStep() {
+        return currentStep;
+    }
+
+    /**
+     * Sets the current Step to the specified Step.
+     *
+     * @param step the new step to set
+     */
+    public void setCurrentStepIndex(int stepIndex) {
+        // Store step index for subsequent requests
+        WizardUils.saveActiveStepIndex(stepIndex);
+        currentStepIndex = stepIndex;
+
+        if (currentStep != null) {
+            removeControl(currentStep);
+        }
+        getModel().remove("heading");
+
+        if (stepIndex == 0) {
+            currentStep = new Step1("step", STEP1_LABEL, STEP1_DESC, this);
+
+        } else if (stepIndex == 1) {
+            currentStep = new Step2("step", STEP2_LABEL, STEP2_DESC, this);
+
+        } else if (stepIndex == 2) {
+            currentStep = new Step3("step", STEP3_LABEL, STEP3_DESC, this);
+        }
+        currentStep.init();
+
+        // Add the new step to the page list of controls
+        addControl(currentStep);
+        addModel("heading", getHeading());
+    }
+
+    /**
+     * Return true if there is another step before the specified step.
+     *
+     * @param step the step to check against
+     * @return true if there is another step before the specified step
+     */
+    public boolean hasPreviousStep() {
+        return currentStepIndex > 0;
+    }
+
+    /**
+     * Return true if there is another step after the specified step.
+     *
+     * @param step the step to check against
+     * @return true if there is another step after the specified step
+     */
+    public boolean hasNextStep() {
+        return !isLastStep();
+    }
+
+    /**
+     * Return true if the specified step is the last step in the process.
+     *
+     * @param step the step to check against
+     * @return true if the specified step is the last step in the process
+     */
+    public boolean isLastStep() {
+        // currentStepIndex is a zero based index. Add 1 when comparing to
+        // numberOfSteps
+        return (numberOfSteps == currentStepIndex + 1);
+    }
+
+    /**
+     * Goto previous step.
+     */
+    public void previous() {
+        if (currentStepIndex > 0) {
+            setCurrentStepIndex(--currentStepIndex);
+        }
+    }
+
+    /**
+     * Goto next step.
+     */
+    public void next() {
+        if (currentStepIndex < numberOfSteps - 1) {
+            setCurrentStepIndex(++currentStepIndex);
+        }
+    }
+
+    /**
+     * Return the page stylesheet: wizard.css.
+     *
+     * @return the page stylesheet
+     */
+    @Override
+    public List getHeadElements() {
+        if (headElements == null) {
+            headElements = super.getHeadElements();
+            headElements.add(new CssImport("/wizard/wizard.css"));
+        }
+        return headElements;
+    }
+
+    // Private Methods --------------------------------------------------------
+
+    /**
+     * Return an HTML representation of the wizard steps as an Html List <ul>.
+     * The current step is assigned a special CSS class so it can be highlighted
+     * through CSS.
+     */
+    private String getHeading() {
+        HtmlStringBuffer buffer = new HtmlStringBuffer();
+        buffer.append("<ul id=\"steps\">");
+        for (int i = 0; i < stepDescriptions.length; i++) {
+            String stepDescription = stepDescriptions[i];
+            String stepLabel = stepLabels[i];
+
+            buffer.elementStart("li");
+            if (stepDescription.equals(currentStep.getDescription())) {
+                buffer.appendAttribute("class", "current");
+            }
+            buffer.closeTag();
+            buffer.append(stepDescription);
+            buffer.elementStart("span");
+            buffer.closeTag();
+            buffer.append(stepLabel);
+            buffer.elementEnd("span");
+            buffer.elementEnd("li");
+        }
+        buffer.append("</ul>");
+        return buffer.toString();
+    }
+}

Added: click/trunk/click/examples/src/org/apache/click/examples/page/wizard/WizardUils.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/wizard/WizardUils.java?rev=1061766&view=auto
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/wizard/WizardUils.java (added)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/wizard/WizardUils.java Fri Jan 21 11:49:01 2011
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.page.wizard;
+
+import org.apache.click.Context;
+import org.apache.click.examples.domain.Client;
+import org.apache.commons.lang.math.NumberUtils;
+
+/**
+ *
+ */
+public class WizardUils {
+
+    public static final String CLIENT_ATTR = "client";
+
+    public static final String STEP_INDEX = "step_index";
+
+    /**
+     * Return the current Client instance in the session.
+     *
+     * @return the current Client instance in the session
+     */
+    public static Client getClientFromSession() {
+        Context context = Context.getThreadLocalContext();
+        Client client = (Client) context.getSessionAttribute(CLIENT_ATTR);
+        return client;
+
+    }
+
+    /**
+     * Save the Client instance in the session.
+     *
+     * @param client the client to store in the session
+     */
+    public static void saveClientInSession(Client client) {
+        Context context = Context.getThreadLocalContext();
+        context.setSessionAttribute(CLIENT_ATTR, client);
+    }
+
+    /**
+     * Remove the currently stored Client instance from the session.
+     */
+    public static void removeClientFromSession() {
+        Context context = Context.getThreadLocalContext();
+        context.removeSessionAttribute(CLIENT_ATTR);
+    }
+
+    public static void saveActiveStepIndex(int index) {
+        Context context = Context.getThreadLocalContext();
+        context.setSessionAttribute(STEP_INDEX, index);
+    }
+
+    public static int restoreActiveStepIndex() {
+        Context context = Context.getThreadLocalContext();
+        Object value = context.getSessionAttribute(STEP_INDEX);
+        int index = value == null ? 0 : (Integer) value;
+        return index;
+    }
+}

Modified: click/trunk/click/examples/src/org/apache/click/examples/service/ClientService.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/service/ClientService.java?rev=1061766&r1=1061765&r2=1061766&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/service/ClientService.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/service/ClientService.java Fri Jan 21 11:49:01 2011
@@ -18,12 +18,16 @@
  */
 package org.apache.click.examples.service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.click.examples.domain.Client;
 import org.apache.click.extras.cayenne.CayenneTemplate;
 
 import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.SortOrder;
+import org.apache.click.examples.domain.Address;
+import org.apache.click.examples.domain.SystemCode;
 import org.springframework.stereotype.Component;
 
 /**
@@ -37,7 +41,7 @@ public class ClientService extends Cayen
     @SuppressWarnings("unchecked")
     public List<Client> getClients() {
         SelectQuery query = new SelectQuery(Client.class);
-        query.addOrdering("db:id", true);
+        query.addOrdering("db:id", SortOrder.ASCENDING);
         return (List<Client>) performQuery(query);
     }
 
@@ -52,9 +56,17 @@ public class ClientService extends Cayen
         commitChanges();
     }
 
-    @SuppressWarnings("deprecation")
-    public Client createClientInNestedContext() {
-        return (Client) getDataContext().createChildDataContext().
-            createAndRegisterNewObject(Client.class);
+    public Client createNewClient() {
+            Client client = newObject(Client.class);
+        return client;
+    }
+
+    public Address createNewAddress() {
+            Address address = newObject(Address.class);
+        return address;
+    }
+
+    public List<SystemCode> getTitles() {
+        return (List<SystemCode>) performQuery("titles", false);
     }
 }



Mime
View raw message