001 package handlingData.complexFormBean;
002
003 import com.bea.wlw.netui.pageflow.FormData;
004 import com.bea.wlw.netui.pageflow.PageFlowController;
005 import com.bea.wlw.netui.pageflow.Forward;
006 import handlingData.complexFormBean.controls.CustomerControl;
007 import handlingData.complexFormBean.controls.CustomerControl.Customer;
008
009 /**
010 * This sample demonstrates how to pre-populate a form and submit it to a page flow using
011 * a FormBean that contains a custom Java object.
012 *
013 * Note that the FormBean CustomerForm contains the custom Java object
014 * complexFormBean.controls.CustomerControl.Customer.
015 *
016 * @jpf:controller
017 * @jpf:forward name="index" path="enterCoupon.jsp"
018 * @jpf:view-properties view-properties::
019 * <!-- This data is auto-generated. Hand-editing this section is not recommended. -->
020 * <view-properties>
021 * <pageflow-object id="pageflow:/handlingData/complexFormBean/complexFormBeanController.jpf"/>
022 * <pageflow-object id="action:begin.do">
023 * <property name="x" value="120"/>
024 * <property name="y" value="60"/>
025 * </pageflow-object>
026 * <pageflow-object id="action:submitCouponNumber.do#handlingData.complexFormBean.complexFormBeanController.CustomerForm">
027 * <property value="300" name="x"/>
028 * <property value="220" name="y"/>
029 * </pageflow-object>
030 * <pageflow-object id="action-call:@page:enterCoupon.jsp@#@action:submitCouponNumber.do#handlingData.complexFormBean.complexFormBeanController.CustomerForm@">
031 * <property value="156,210,210,264" name="elbowsX"/>
032 * <property value="212,212,212,212" name="elbowsY"/>
033 * <property value="East_1" name="fromPort"/>
034 * <property value="West_1" name="toPort"/>
035 * </pageflow-object>
036 * <pageflow-object id="page:enterCoupon.jsp">
037 * <property name="x" value="120"/>
038 * <property name="y" value="220"/>
039 * </pageflow-object>
040 * <pageflow-object id="action-call:@page:thankyou.jsp@#@action:begin.do@">
041 * <property value="264,210,210,156" name="elbowsX"/>
042 * <property value="52,52,52,52" name="elbowsY"/>
043 * <property value="West_1" name="fromPort"/>
044 * <property value="East_1" name="toPort"/>
045 * </pageflow-object>
046 * <pageflow-object id="page:thankyou.jsp">
047 * <property value="300" name="x"/>
048 * <property value="60" name="y"/>
049 * </pageflow-object>
050 * <pageflow-object id="forward:path#success#enterCoupon.jsp#@action:begin.do@">
051 * <property value="120,120,120,120" name="elbowsX"/>
052 * <property value="104,140,140,176" name="elbowsY"/>
053 * <property value="South_1" name="fromPort"/>
054 * <property value="North_1" name="toPort"/>
055 * <property value="success" name="label"/>
056 * </pageflow-object>
057 * <pageflow-object id="forward:path#success#thankyou.jsp#@action:submitCouponNumber.do#handlingData.complexFormBean.complexFormBeanController.CustomerForm@">
058 * <property value="300,300,300,300" name="elbowsX"/>
059 * <property value="176,140,140,104" name="elbowsY"/>
060 * <property value="North_1" name="fromPort"/>
061 * <property value="South_1" name="toPort"/>
062 * <property value="success" name="label"/>
063 * </pageflow-object>
064 * <pageflow-object id="forward:path#failed#enterCoupon.jsp#@action:submitCouponNumber.do#handlingData.complexFormBean.complexFormBeanController.CustomerForm@">
065 * <property value="264,210,210,156" name="elbowsX"/>
066 * <property value="212,212,212,212" name="elbowsY"/>
067 * <property value="West_1" name="fromPort"/>
068 * <property value="East_1" name="toPort"/>
069 * <property value="failed" name="label"/>
070 * </pageflow-object>
071 * <pageflow-object id="control:handlingData.complexFormBean.controls.CustomerControl#customerControl">
072 * <property value="46" name="x"/>
073 * <property value="34" name="y"/>
074 * </pageflow-object>
075 * <pageflow-object id="formbeanprop:handlingData.complexFormBean.complexFormBeanController.CustomerForm#customer#handlingData.complexFormBean.controls.CustomerControl.Customer"/>
076 * <pageflow-object id="formbeanprop:handlingData.complexFormBean.complexFormBeanController.CustomerForm#couponNumber#java.lang.String"/>
077 * <pageflow-object id="formbean:handlingData.complexFormBean.complexFormBeanController.CustomerForm"/>
078 * <pageflow-object id="forward:path#index#enterCoupon.jsp"/>
079 * </view-properties>
080 * ::
081 */
082 public class complexFormBeanController extends PageFlowController
083 {
084 /**
085 * @common:control
086 */
087 private handlingData.complexFormBean.controls.CustomerControl customerControl;
088
089 public String message;
090
091 /**
092 * When the pageflow is first invoked, forward the user to the enterCoupon.jsp
093 * page and pre-populate the form fields on that page.
094 *
095 * Note that the FormBean CustomerForm is forwarded to the enterCoupon.jsp page,
096 * so that the fields on that page are pre-populated with values.
097 *
098 * @jpf:action
099 * @jpf:forward name="success" path="enterCoupon.jsp"
100 */
101 protected Forward begin()
102 {
103 message="";
104 CustomerForm form = new CustomerForm();
105 form.setCustomer(customerControl.getCustomer(42));
106
107 return new Forward("success", form);
108 }
109
110 /**
111 * @jpf:action
112 * @jpf:forward name="success" path="thankyou.jsp"
113 * @jpf:forward name="failed" path="enterCoupon.jsp"
114 */
115 protected Forward submitCouponNumber(CustomerForm form)
116 {
117 /*
118 * In a real-world situation, you would do something here with the data from the form,
119 * such as enter the data in a database, or run some other business process.
120 */
121 boolean outcome = customerControl.updateCustomer(form.getCustomer(), form.getCouponNumber());
122 /*
123 * If the updateCustomer method returns true, forward the user to the
124 * thankyou.jsp page.
125 */
126 if(outcome == true)
127 return new Forward("success", form);
128 /*
129 * If the updateCustomer method returns false, send the user back to the
130 * enterCoupon.jsp page.
131 */
132 else {
133 message="Submission failed. Please try again";
134 return new Forward("failed");
135 }
136 }
137
138 /**
139 * The following FormBean has two uses in this page flow.
140 *
141 * (1) It is used to pre-populate the fields of the enterCoupon.jsp page (see the begin method).
142 *
143 * (2) It is used to submit values from the enterCoupon.jsp page.
144 *
145 * These two uses cannot be accomplished by a single instance of the FormBean.
146 * That is why we have included the reset method in the FormBean below.
147 * The reset method allows the Workshop runtime to create two instances of the
148 * FormBean for one pre-population / submission cycle.
149 */
150 public static class CustomerForm extends FormData
151 {
152 private String couponNumber;
153
154 private Customer customer;
155
156 public void setCustomer(Customer customer)
157 {
158 this.customer = customer;
159 }
160
161 public Customer getCustomer()
162 {
163 return this.customer;
164 }
165
166 public void reset(org.apache.struts.action.ActionMapping mapping,
167 javax.servlet.http.HttpServletRequest request)
168 {
169 // Create an instance of the bean when
170 // the data is submitted to the page flow.
171 this.customer = new Customer();
172 }
173
174 public void setCouponNumber(java.lang.String couponNumber)
175 {
176 this.couponNumber = couponNumber;
177 }
178
179 public java.lang.String getCouponNumber()
180 {
181 return this.couponNumber;
182 }
183 }
184
185
186 }
|