001 /*
002 * The JSP pages in this sample use the <netui-data:callPageFlow> tag
003 * to invoke methods defined in this page flow file.
004 */
005 package tagSamples.netui_databinding.callPageFlow;
006
007 // java imports
008 import java.io.Serializable;
009
010 import java.util.ArrayList;
011 import java.util.List;
012
013 // internal imports
014 import com.bea.wlw.netui.pageflow.PageFlowController;
015 import com.bea.wlw.netui.pageflow.Forward;
016
017 // external imports
018
019 /**
020 *
021 * @jpf:view-properties view-properties::
022 * <!-- This data is auto-generated. Hand-editing this section is not recommended. -->
023 * <view-properties>
024 * <pageflow-object id="pageflow:/tagSamples/netui_databinding/callPageFlow/callPageFlowController.jpf"/>
025 * <pageflow-object id="action:Sum.do">
026 * <property value="220" name="x"/>
027 * <property value="60" name="y"/>
028 * </pageflow-object>
029 * <pageflow-object id="action:Simple.do">
030 * <property value="340" name="x"/>
031 * <property value="60" name="y"/>
032 * </pageflow-object>
033 * <pageflow-object id="action:begin.do">
034 * <property value="100" name="x"/>
035 * <property value="60" name="y"/>
036 * </pageflow-object>
037 * <pageflow-object id="action-call:@page:sum.jsp@#@action:begin.do@">
038 * <property value="184,160,160,136" name="elbowsX"/>
039 * <property value="212,212,52,52" name="elbowsY"/>
040 * <property value="West_1" name="fromPort"/>
041 * <property value="East_1" name="toPort"/>
042 * </pageflow-object>
043 * <pageflow-object id="page:sum.jsp">
044 * <property value="220" name="x"/>
045 * <property value="220" name="y"/>
046 * </pageflow-object>
047 * <pageflow-object id="action-call:@page:simple.jsp@#@action:begin.do@">
048 * <property value="304,220,220,136" name="elbowsX"/>
049 * <property value="212,212,63,63" name="elbowsY"/>
050 * <property value="West_1" name="fromPort"/>
051 * <property value="East_2" name="toPort"/>
052 * </pageflow-object>
053 * <pageflow-object id="page:simple.jsp">
054 * <property value="340" name="x"/>
055 * <property value="220" name="y"/>
056 * </pageflow-object>
057 * <pageflow-object id="page:index.jsp">
058 * <property value="100" name="x"/>
059 * <property value="220" name="y"/>
060 * </pageflow-object>
061 * <pageflow-object id="forward:path#Sum#sum.jsp#@action:Sum.do@">
062 * <property value="104,140,140,176" name="elbowsY"/>
063 * <property value="North_1" name="toPort"/>
064 * <property value="220,220,220,220" name="elbowsX"/>
065 * <property value="Sum" name="label"/>
066 * <property value="South_1" name="fromPort"/>
067 * </pageflow-object>
068 * <pageflow-object id="forward:path#Simple#simple.jsp#@action:Simple.do@">
069 * <property value="104,140,140,176" name="elbowsY"/>
070 * <property value="North_1" name="toPort"/>
071 * <property value="340,340,340,340" name="elbowsX"/>
072 * <property value="Simple" name="label"/>
073 * <property value="South_1" name="fromPort"/>
074 * </pageflow-object>
075 * <pageflow-object id="forward:path#index#index.jsp#@action:begin.do@">
076 * <property value="104,140,140,176" name="elbowsY"/>
077 * <property value="100,100,100,100" name="elbowsX"/>
078 * <property value="North_1" name="toPort"/>
079 * <property value="South_1" name="fromPort"/>
080 * <property value="index" name="label"/>
081 * </pageflow-object>
082 * </view-properties>
083 * ::
084 *
085 */
086 public class callPageFlowController extends PageFlowController
087 {
088 private String defaultText = "Hello World!";
089
090 private Cart cart = null;
091
092 public String getDefaultText()
093 {
094 return defaultText;
095 }
096
097 public String echo(String echo)
098 {
099 return echo;
100 }
101
102 public Cart getCart()
103 {
104 return cart;
105 }
106
107 public Double sumCartItems(List items)
108 {
109 if(items == null) return new Double(0);
110
111 double sum = 0.0;
112 for(int i = 0; i < items.size(); i++)
113 {
114 LineItem item = (LineItem)items.get(i);
115 // sum += item.getQuantity() * item.getPrice();
116 sum += item.getTotal();
117 }
118
119 return new Double(sum);
120 }
121
122 public String getShippingState(int shipState)
123 {
124 if(shipState == LineItem.IN_TRANSIT)
125 return "inTransit";
126 else if(shipState == LineItem.NOT_SHIPPED)
127 return "notShipped";
128 else if(shipState == LineItem.ARRIVED)
129 return "arrived";
130 else return "unknown";
131 }
132
133 /**
134 * @jpf:action
135 * @jpf:forward name="Sum" path="sum.jsp"
136 */
137 public Forward Sum()
138 {
139 if(cart == null)
140 cart = initCart();
141
142 return new Forward("Sum");
143 }
144
145 /**
146 * @jpf:action
147 * @jpf:forward name="Simple" path="simple.jsp"
148 */
149 public Forward Simple()
150 {
151 return new Forward("Simple");
152 }
153
154 /**
155 * @jpf:action
156 * @jpf:forward name="index" path="index.jsp"
157 */
158 public Forward begin()
159 {
160 cart = initCart();
161 return new Forward("index");
162 }
163
164 private Cart initCart()
165 {
166 Cart c = new Cart();
167 c.addItem(new LineItem("Product A", 3, 9.95, 1));
168 c.addItem(new LineItem("Product C", 2, 19.95, 2));
169 c.addItem(new LineItem("Product B", 5, 29.95, 3));
170 c.addItem(new LineItem("Product D", 1, 39.95, 4));
171 c.addItem(new LineItem("Product E", 3, 59.95, 3));
172 c.addItem(new LineItem("Product F", 2, 1.95, 2));
173 c.addItem(new LineItem("Product G", 2, 4.95, 2));
174
175 return c;
176 }
177
178 public static class Cart
179 implements Serializable
180 {
181 private List items = null;
182
183 public void addItem(LineItem item)
184 {
185 if(items == null) items = new ArrayList();
186
187 items.add(item);
188 }
189
190 public List getLineItemList()
191 {
192 return items;
193 }
194
195 public LineItem[] getLineItemArray()
196 {
197 if(items == null) return null;
198 else return (LineItem[])items.toArray();
199 }
200 }
201
202 public static class LineItem
203 implements Serializable
204 {
205 public static final int NOT_SHIPPED = 1;
206 public static final int IN_TRANSIT = 2;
207 public static final int ARRIVED = 3;
208 public static final int UNKNOWN = 4;
209
210 private String name = null;
211 private int quantity = 0;
212 private double price = 0.0;
213 private double total = 0.0;
214 private int shipState = NOT_SHIPPED;
215
216 public LineItem(String name, int quantity, double price, int shipState)
217 {
218 this.name = name;
219 this.quantity = quantity;
220 this.price = price;
221 this.total = price * quantity;
222 this.shipState = shipState;
223 }
224
225 public String getName() {return name;}
226 public double getPrice() {return price;}
227 public int getQuantity() {return quantity;}
228 public double getTotal() {return total;}
229 public int getShipState() {return shipState;}
230 }
231 }
|