KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > continuations > Order


1 package demo.continuations;
2
3 import com.uwyn.rife.continuations.ContinuationContext;
4 import com.uwyn.rife.engine.Element;
5 import com.uwyn.rife.engine.annotations.Elem;
6 import com.uwyn.rife.engine.annotations.Param;
7 import com.uwyn.rife.engine.annotations.Submission;
8 import com.uwyn.rife.engine.annotations.SubmissionBean;
9 import com.uwyn.rife.site.ValidatedConstrained;
10 import com.uwyn.rife.template.Template;
11
12 /**
13  * This element handles a basic multi-step order checkout process. <p>
14  *
15  * Continuations are used to handle the intermediate data submissions. By
16  * providing a custom <code>clone()</code> implementation, the individual
17  * steps are prefilled with earlier submitted data if the user has pressed
18  * the back button.
19  *
20  *@author Geert Bevin (gbevin[remove] at uwyn dot com)
21  *@version $Revision: 2281 $
22  */

23 @Elem(
24          submissions={
25          @Submission(
26             name="selectShipping",
27             beans={@SubmissionBean(beanclass=OrderData.class, group=OrderDataMetaData.GROUP_SHIPPING) }) ,
28          @Submission(
29       name="provideCreditCard",
30       beans={@SubmissionBean(beanclass=OrderData.class, group=OrderDataMetaData.GROUP_CREDITCARD) },
31       params={@Param(name=Order.PARAM_BACK) })
32          })
33 public class Order extends Element {
34
35    private OrderData order = new OrderData();
36    /**
37     * Description of the Field
38     */

39    public static final String JavaDoc PARAM_BACK = "back";
40
41    public void processElement() {
42       Template template = getHtmlTemplate("order");
43
44       // handle the submission of the shipping details
45
do {
46          generateForm(template, order);
47          template.setBlock("content_form", "content_shipping");
48          print(template);
49          pause();
50
51          template.clear();
52          ((ValidatedConstrained) order).resetValidation();
53          fillSubmissionBean(order);
54       } while (duringStepBack() || !((ValidatedConstrained) order).validateGroup(OrderDataMetaData.GROUP_SHIPPING));
55
56       // handle the submission of the credit card details
57
do {
58          generateForm(template, order);
59          template.setBlock("content_form", "content_creditcard");
60          print(template);
61          pause();
62
63          template.clear();
64          ((ValidatedConstrained) order).resetValidation();
65          fillSubmissionBean(order);
66          if (hasParameterValue(PARAM_BACK)) {
67             stepBack();
68          }
69       } while (!((ValidatedConstrained) order).validateGroup(OrderDataMetaData.GROUP_CREDITCARD));
70
71       // provide an overview of everything that has been submitted
72
template.setBean(order);
73       template.setBlock("content", "content_overview");
74       print(template);
75
76       // remove any continuation contexts that are active in this tree
77
ContinuationContext.getActiveContext().removeContextTree();
78    }
79
80    public Object JavaDoc clone()
81           throws CloneNotSupportedException JavaDoc {
82       // This clone implementation uses the standard Element clone method.
83
// The order member variable will be preserved as-is however.
84
// The result is that even when the user presses the back button and
85
// re-submits a previous step, the earlier submitted data will be
86
// used to automatically fill in the already answered steps.
87
Order cloned = (Order) super.clone();
88       cloned.order = order;
89
90       return cloned;
91    }
92 }
93
Popular Tags