/*
* Copyright 2001-2006 Geert Bevin <gbevin[remove] at uwyn dot com>
* Distributed under the terms of either:
* - the common development and distribution license (CDDL), v1.0; or
* - the GNU Lesser General Public License, v2.1 or later
* $Id: Order.java 3364 2006-07-10 10:33:29Z gbevin $
*/
import com.uwyn.rife.engine.ContinuationContext;
import com.uwyn.rife.engine.Element;
import com.uwyn.rife.template.Template;
/**
* This element handles a basic multi-step order checkout process.
* <p>
* Continuations are used to handle the intermediate data submissions.
* By providing a custom <code>clone()</code> implementation, the
* individual steps are prefilled with earlier submitted data
* if the user has pressed the back button.
*
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
* @version $Revision: 3364 $
*/
public class Order extends Element {
private OrderData order = new OrderData();
public void processElement() {
Template template = getHtmlTemplate("order");
// handle the submission of the shipping details
do {
generateForm(template, order);
template.setBlock("content_form", "content_shipping");
print(template);
pause();
template.clear();
order.resetValidation();
fillSubmissionBean(order);
} while (duringStepBack() || !order.validateGroup("shipping"));
// handle the submission of the credit card details
do {
generateForm(template, order);
template.setBlock("content_form", "content_creditcard");
print(template);
pause();
template.clear();
order.resetValidation();
fillSubmissionBean(order);
if (hasParameterValue("back1")) stepBack();
} while (duringStepBack() || !order.validateGroup("creditcard"));
// provide an overview of everything that has been submitted
template.setBean(order);
template.setBlock("content", "content_overview");
print(template);
// remove any continuation contexts that are active in this tree
ContinuationContext.getActiveContext().removeContextTree();
}
public Object clone()
throws CloneNotSupportedException {
// This clone implementation uses the standard Element clone method.
// The order member variable will be preserved as-is however.
// The result is that even when the user presses the back button and
// re-submits a previous step, the earlier submitted data will be
// used to automatically fill in the already answered steps.
Order cloned = (Order)super.clone();
cloned.order = order;
return cloned;
}
}