You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/11/02 21:32:15 UTC
svn commit: r330352 - in /beehive/trunk/samples/petstoreWeb:
src/org/apache/beehive/samples/petstore/controller/
src/org/apache/beehive/samples/petstore/forms/
src/org/apache/beehive/samples/petstore/model/
src/org/apache/beehive/samples/petstore/model...
Author: ekoneil
Date: Wed Nov 2 12:31:57 2005
New Revision: 330352
URL: http://svn.apache.org/viewcvs?rev=330352&view=rev
Log:
Cleanup in the petstoreWeb sample.
- fixing up a bunch of page flow controllers
- removing web service samples which weren't enabled
BB: self
Test: petstoreWeb HTTPUnit tests pass
Added:
beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CartForm.java (with props)
beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CreateAccountForm.java (with props)
beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CreateAddressForm.java (with props)
beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/SecurityCheckForm.java (with props)
beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/UpdateAccountForm.java (with props)
beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/util/
beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/util/DBProperties.java (with props)
Removed:
beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/model/ws/
beehive/trunk/samples/petstoreWeb/web/WEB-INF/server-config.wsdd
Modified:
beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controller/AccountController.java
beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/model/Order.java
beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/model/OrderItem.java
beehive/trunk/samples/petstoreWeb/web/Controller.java
beehive/trunk/samples/petstoreWeb/web/WEB-INF/web.xml
beehive/trunk/samples/petstoreWeb/web/account/addresses/Controller.java
beehive/trunk/samples/petstoreWeb/web/account/create/Controller.java
beehive/trunk/samples/petstoreWeb/web/account/create/create.jsp
beehive/trunk/samples/petstoreWeb/web/account/edit/Controller.java
beehive/trunk/samples/petstoreWeb/web/auth/Controller.java
beehive/trunk/samples/petstoreWeb/web/checkout/Controller.java
beehive/trunk/samples/petstoreWeb/web/index.jsp
beehive/trunk/samples/petstoreWeb/web/search/index.jsp
beehive/trunk/samples/petstoreWeb/web/shop/Controller.java
beehive/trunk/samples/petstoreWeb/web/webappRoot/SharedFlow.java
Modified: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controller/AccountController.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controller/AccountController.java?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controller/AccountController.java (original)
+++ beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/controller/AccountController.java Wed Nov 2 12:31:57 2005
@@ -22,9 +22,13 @@
public abstract class AccountController
extends PageFlowController {
- protected static final String[] LANGUAGES;
+ private static final String[] LANGUAGES;
static {
LANGUAGES = new String[]{"English", "Japanese"};
+ }
+
+ protected static String[] getLanguages() {
+ return LANGUAGES;
}
}
Added: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CartForm.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CartForm.java?rev=330352&view=auto
==============================================================================
--- beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CartForm.java (added)
+++ beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CartForm.java Wed Nov 2 12:31:57 2005
@@ -0,0 +1,55 @@
+/**
+ Copyright 2004 The Apache Software Foundation.
+
+ Licensed 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.
+
+ $Header:$
+ */
+package org.apache.beehive.samples.petstore.forms;
+
+import java.util.List;
+import java.io.Serializable;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.beehive.netui.pageflow.Validatable;
+import org.apache.beehive.samples.petstore.model.Cart;
+import org.apache.beehive.samples.petstore.model.LineItem;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionError;
+import org.apache.struts.action.ActionMessages;
+
+/**
+ *
+ */
+public class CartForm
+ implements Serializable, Validatable {
+
+ private Cart _cart;
+
+ public void setCart(Cart cart) {
+ _cart = cart;
+ }
+
+ public Cart getCart() {
+ return _cart;
+ }
+
+ public void validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest, ActionMessages actionMessages) {
+ List<LineItem> items = getCart().getLineItems();
+ if(items != null && items.size() > 0) {
+ for(int i = 0; i < items.size(); i++) {
+ actionMessages.add("invalidQuantity" + i, new ActionError("order.error.invalidQuantity"));
+ }
+ }
+ }
+}
Propchange: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CartForm.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CreateAccountForm.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CreateAccountForm.java?rev=330352&view=auto
==============================================================================
--- beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CreateAccountForm.java (added)
+++ beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CreateAccountForm.java Wed Nov 2 12:31:57 2005
@@ -0,0 +1,80 @@
+/**
+ Copyright 2004 The Apache Software Foundation.
+
+ Licensed 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.
+
+ $Header:$
+ */
+package org.apache.beehive.samples.petstore.forms;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.beehive.samples.petstore.model.Account;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionError;
+
+/**
+ *
+ */
+public class CreateAccountForm
+ extends AccountForm {
+
+ private String _repeatedPassword;
+
+ public CreateAccountForm() {
+ super();
+ }
+
+ public CreateAccountForm(Account account) {
+ super(account);
+ }
+
+ public void setUserId(String userId) {
+ getAccount().setUserId(userId);
+ }
+
+ public String getPassword() {
+ return getAccount().getPassword();
+ }
+
+ public void setPassword(String password) {
+ getAccount().setPassword(password);
+ }
+
+ public String getRepeatedPassword() {
+ return _repeatedPassword;
+ }
+
+ public void setRepeatedPassword(String repeatedPassword) {
+ _repeatedPassword = repeatedPassword;
+ }
+
+ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
+ ActionErrors errors = new ActionErrors();
+ Account account = getAccount();
+ account.setStatus("OK");
+
+ addErrorIfStringEmpty(errors, "userId", "account.error.userid.required", account.getUserId());
+
+ if(account.getPassword() == null ||
+ account.getPassword().length() < 1 ||
+ !account.getPassword().equals(getRepeatedPassword())) {
+ errors.add("repeatedPassword", new ActionError("account.error.password.missing"));
+ }
+
+ baseValidate(errors, mapping, request);
+
+ return errors;
+ }
+}
Propchange: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CreateAccountForm.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CreateAddressForm.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CreateAddressForm.java?rev=330352&view=auto
==============================================================================
--- beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CreateAddressForm.java (added)
+++ beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CreateAddressForm.java Wed Nov 2 12:31:57 2005
@@ -0,0 +1,54 @@
+/**
+ Copyright 2004 The Apache Software Foundation.
+
+ Licensed 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.
+
+ $Header:$
+ */
+package org.apache.beehive.samples.petstore.forms;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.beehive.samples.petstore.model.Address;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionMapping;
+
+/**
+ *
+ */
+public class CreateAddressForm
+ extends AddressForm {
+
+ public CreateAddressForm() {
+ super();
+ }
+
+ public CreateAddressForm(Address address) {
+ super(address);
+ }
+
+ public void setUserId(String userId) {
+ getAddress().setUserId(userId);
+ }
+
+ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
+ ActionErrors errors = new ActionErrors();
+ Address address = getAddress();
+
+ addErrorIfStringEmpty(errors, "userId", "address.error.userid.required", address.getUserId());
+
+ baseValidate(errors, mapping, request);
+
+ return errors;
+ }
+}
Propchange: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/CreateAddressForm.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/SecurityCheckForm.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/SecurityCheckForm.java?rev=330352&view=auto
==============================================================================
--- beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/SecurityCheckForm.java (added)
+++ beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/SecurityCheckForm.java Wed Nov 2 12:31:57 2005
@@ -0,0 +1,46 @@
+/**
+ Copyright 2004 The Apache Software Foundation.
+
+ Licensed 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.
+
+ $Header:$
+ */
+package org.apache.beehive.samples.petstore.forms;
+
+import org.apache.beehive.netui.pageflow.FormData;
+
+/**
+ *
+ */
+public class SecurityCheckForm
+ extends FormData {
+
+ private String _j_username;
+ private String _j_password;
+
+ public void setj_password(String j_password) {
+ _j_password = j_password;
+ }
+
+ public String getj_password() {
+ return _j_password;
+ }
+
+ public void setj_username(String j_username) {
+ _j_username = j_username;
+ }
+
+ public String getj_username() {
+ return _j_username;
+ }
+}
Propchange: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/SecurityCheckForm.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/UpdateAccountForm.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/UpdateAccountForm.java?rev=330352&view=auto
==============================================================================
--- beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/UpdateAccountForm.java (added)
+++ beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/UpdateAccountForm.java Wed Nov 2 12:31:57 2005
@@ -0,0 +1,64 @@
+/**
+ Copyright 2004 The Apache Software Foundation.
+
+ Licensed 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.
+
+ $Header:$
+ */
+package org.apache.beehive.samples.petstore.forms;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.beehive.samples.petstore.model.Account;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionMapping;
+
+/**
+ *
+ */
+public class UpdateAccountForm
+ extends AccountForm {
+
+ private String _newPassword;
+ private String _repeatedPassword;
+
+ public UpdateAccountForm() {
+ super();
+ }
+
+ public UpdateAccountForm(Account account) {
+ super(account);
+ }
+
+ public String getNewPassword() {
+ return _newPassword;
+ }
+
+ public void setNewPassword(String value) {
+ _newPassword = value;
+ }
+
+ public String getRepeatedPassword() {
+ return _repeatedPassword;
+ }
+
+ public void setRepeatedPassword(String value) {
+ _repeatedPassword = value;
+ }
+
+ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
+ ActionErrors errors = new ActionErrors();
+ baseValidate(errors, mapping, request);
+ return errors;
+ }
+}
Propchange: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/forms/UpdateAccountForm.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/model/Order.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/model/Order.java?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/model/Order.java (original)
+++ beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/model/Order.java Wed Nov 2 12:31:57 2005
@@ -27,22 +27,12 @@
private Date _orderDate;
private Date _time;
-
- //private String _courier;
private BigDecimal _totalPrice;
-
private String _creditCard;
private String _exprDate;
private String _cardType;
- //private String _locale;
private String _status;
-
- //private int _lineNum;
-
- //private Account _account = null;
- //private Cart _cart = null;
private String _userId;
-
private int _shippingAddress = -1;
private int _billingAddress = -1;
@@ -50,21 +40,6 @@
_userId = userId;
_totalPrice = cart.getSubTotal();
}
-/*
- public void initOrder(Account account, Cart cart) {
- _account = account;
- _cart = cart;
- _orderDate = new Date();
- _totalPrice = _cart.getSubTotal();
- }
-
- public Account getAccount() {
- return _account;
- } */
-
- /* public Cart getCart() {
- return _cart;
- }*/
public int getOrderId() {
return _orderId;
@@ -89,14 +64,6 @@
public void setTime(Date time) {
_time = time;
}
-/*
- public String getCourier() {
- return _courier;
- }
-
- public void setCourier(String courier) {
- _courier = courier;
- } */
public BigDecimal getTotalPrice() {
return _totalPrice;
@@ -129,15 +96,7 @@
public void setCardType(String cardType) {
_cardType = cardType;
}
-/*
- public String getLocale() {
- return _locale;
- }
- public void setLocale(String locale) {
- _locale = locale;
- }
-*/
public String getStatus() {
return _status;
}
@@ -145,15 +104,7 @@
public void setStatus(String status) {
_status = status;
}
-/*
- public int getLineNum() {
- return _lineNum;
- }
- public void setLineNum(int lineNum) {
- _lineNum = lineNum;
- }
-*/
public int getShippingAddress() {
return _shippingAddress;
}
@@ -177,7 +128,4 @@
public String getUserId() {
return _userId;
}
- //private Address createAddress() {
- // return new Address();
- //}
}
Modified: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/model/OrderItem.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/model/OrderItem.java?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/model/OrderItem.java (original)
+++ beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/model/OrderItem.java Wed Nov 2 12:31:57 2005
@@ -17,9 +17,6 @@
*/
package org.apache.beehive.samples.petstore.model;
-/**
- *
- */
public class OrderItem
extends Item {
@@ -32,6 +29,4 @@
public void setQuantity(int quantity) {
_quantity = quantity;
}
-
-
}
Added: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/util/DBProperties.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/util/DBProperties.java?rev=330352&view=auto
==============================================================================
--- beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/util/DBProperties.java (added)
+++ beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/util/DBProperties.java Wed Nov 2 12:31:57 2005
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.samples.petstore.util;
+
+public interface DBProperties {
+ public static final String DATABASE_LOCATION = "c:/Apache/Derby/petDB";
+
+
+}
Propchange: beehive/trunk/samples/petstoreWeb/src/org/apache/beehive/samples/petstore/util/DBProperties.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/samples/petstoreWeb/web/Controller.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/web/Controller.java?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/web/Controller.java (original)
+++ beehive/trunk/samples/petstoreWeb/web/Controller.java Wed Nov 2 12:31:57 2005
@@ -16,32 +16,28 @@
* $Header:$
*/
import java.io.BufferedReader;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.LinkedList;
import org.apache.beehive.controls.api.bean.Control;
import org.apache.beehive.netui.pageflow.PageFlowController;
import org.apache.beehive.netui.pageflow.Forward;
import org.apache.beehive.netui.pageflow.annotations.Jpf;
import org.apache.beehive.samples.petstore.controls.CatalogControl;
-import org.apache.beehive.samples.petstore.controls.data.DBProperties;
+import org.apache.beehive.samples.petstore.util.DBProperties;
import org.apache.beehive.samples.petstore.controls.exceptions.DataStoreException;
import webappRoot.SharedFlow;
@Jpf.Controller(
- sharedFlowRefs={
- @Jpf.SharedFlowRef(name="rootSharedFlow", type=webappRoot.SharedFlow.class)
- }
+ forwards={@Jpf.Forward(name="index", path="index.jsp")},
+ sharedFlowRefs={@Jpf.SharedFlowRef(name="rootSharedFlow", type=webappRoot.SharedFlow.class)}
)
public class Controller
- extends PageFlowController
-{
+ extends PageFlowController {
+
private static final String SQL_FILE = "sql/initDB.sql";
@Jpf.SharedFlowField(name="rootSharedFlow")
@@ -49,83 +45,80 @@
@Control()
private CatalogControl _catalogControl;
-
+
@Jpf.Action(
forwards = {
- @Jpf.Forward(name = "shop", path = "/shop/Controller.jpf"),
- @Jpf.Forward(name = "index", path = "/index.jsp")
+ @Jpf.Forward(name = "shop", path = "/shop/Controller.jpf")
}
)
- protected Forward begin()
- {
+ public Forward begin() {
if (_sharedFlow.isUserLoggedIn())
return new Forward("shop");
- else
- return new Forward("index");
+ else return new Forward("index");
+ }
+
+ @Jpf.Action()
+ public Forward stopDB()
+ throws Exception {
+
+ /* move this code... */
+ try {
+ java.sql.DriverManager.getConnection("jdbc:derby:" + DBProperties.DATABASE_LOCATION + ";shutdown=true");
+ }
+ catch(Exception e) {}
+
+ getRequest().setAttribute("message", "DB Stopped.");
+ return new Forward("index");
}
+
+ @Jpf.Action()
+ public Forward initDB()
+ throws Exception {
+ LinkedList<String> dbInit = getSqlStatements(SQL_FILE);
- @Jpf.Action(
- forwards = {
- @Jpf.Forward(name = "success", path = "index.jsp")
+ for(String sql : dbInit) {
+ try {
+ _catalogControl.initDB(sql);
+ }
+ catch(DataStoreException e) {
+ // Ignore exceptions on DROP statements since the tables may simply not exist
+ if (!sql.startsWith("drop"))
+ throw e;
}
- )
- public Forward stopDB() throws Exception
- {
- try {
- java.sql.DriverManager.getConnection("jdbc:derby:" + DBProperties.dbLocation + ";shutdown=true");
- } catch (Exception e) {}
- getRequest().setAttribute("message", "DB Stopped.");
- return new Forward("success");
}
-
- @Jpf.Action(
- forwards = {
- @Jpf.Forward(name = "index", path = "index.jsp")
- }
- )
- protected Forward initDB() throws Exception
- {
- List<String> dbInit = getSqlStatements(SQL_FILE);
-
- for(String sql : dbInit)
- {
- try {
- _catalogControl.initDB(sql);
- } catch (DataStoreException e) {
- // Ignore errors on the drop action since the table may not exist
- if (!sql.startsWith("drop"))
- throw e;
- }
- }
- getRequest().setAttribute("message", "DB Initialized.");
-
- return new Forward("index");
- }
-
- private List<String> getSqlStatements(String sqlFile) throws Exception
- {
- InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(sqlFile);
- BufferedReader fs = new BufferedReader(new InputStreamReader(is));
- List<String> statements = new ArrayList<String>();
+ getRequest().setAttribute("message", "DB Initialized.");
+
+ return new Forward("index");
+ }
+
+ private LinkedList<String> getSqlStatements(String sqlFile)
+ throws Exception {
+
+ InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(sqlFile);
+ BufferedReader fs = new BufferedReader(new InputStreamReader(is));
+ LinkedList<String> statements = new LinkedList<String>();
try {
String line = null;
while((line = fs.readLine()) != null)
- {
- // Ignore comments and empty lines
- if (line.endsWith(";") && !(line.startsWith("--")))
+ {
+ // Ignore comments and empty lines
+ if (line.endsWith(";") && !(line.startsWith("--")))
statements.add(line.replace(';', ' '));
}
- } catch(IOException io) {
- throw new RuntimeException("Unable to read input stream: " + sqlFile);
- } finally {
+ }
+ catch(IOException io) {
+ throw new IllegalStateException("Unable to read input stream: " + sqlFile);
+ }
+ finally {
try {
if(fs != null) fs.close();
} catch(Exception ignore) {}
- }
+ }
+
for(String s : statements) {
System.out.println(s + "\n");
}
return statements;
- }
+ }
}
Modified: beehive/trunk/samples/petstoreWeb/web/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/web/WEB-INF/web.xml?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/web/WEB-INF/web.xml (original)
+++ beehive/trunk/samples/petstoreWeb/web/WEB-INF/web.xml Wed Nov 2 12:31:57 2005
@@ -5,7 +5,7 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
- <display-name>PageFlow Petstore Application</display-name>
+ <display-name>Beehive Petstore Application</display-name>
<filter>
<filter-name>ControlFilter</filter-name>
@@ -18,11 +18,6 @@
</filter>
<filter-mapping>
- <filter-name>ControlFilter</filter-name>
- <url-pattern>*.jws</url-pattern>
- </filter-mapping>
-
- <filter-mapping>
<filter-name>PageFlowJspFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
<dispatcher>FORWARD</dispatcher>
@@ -30,11 +25,6 @@
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
- <servlet>
- <servlet-name>AxisServlet</servlet-name>
- <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
- </servlet>
-
<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>action</servlet-name>
@@ -63,11 +53,6 @@
</servlet-mapping>
<servlet-mapping>
- <servlet-name>AxisServlet</servlet-name>
- <url-pattern>*.jws</url-pattern>
- </servlet-mapping>
-
- <servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
@@ -76,30 +61,6 @@
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
-<!--
- <security-constraint>
- <web-resource-collection>
- <web-resource-name>AccountPageFlow</web-resource-name>
- <description>Protect the page flow that allows account manipulation.</description>
- <url-pattern>/account/*</url-pattern>
- <http-method>GET</http-method>
- </web-resource-collection>
- <web-resource-collection>
- <web-resource-name>AccountPageFlow</web-resource-name>
- <description>Protect the page flow that allows checkout.</description>
- <url-pattern>/checkout/*</url-pattern>
- <http-method>GET</http-method>
- </web-resource-collection>
- <auth-constraint>
- <description>Roles who have access to the account manipulation pages.</description>
- <role-name>Users</role-name>
- </auth-constraint>
- <user-data-constraint>
- <description>This is how the user data must be transmitted.</description>
- <transport-guarantee>NONE</transport-guarantee>
- </user-data-constraint>
- </security-constraint>
--->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>default</realm-name>
Modified: beehive/trunk/samples/petstoreWeb/web/account/addresses/Controller.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/web/account/addresses/Controller.java?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/web/account/addresses/Controller.java (original)
+++ beehive/trunk/samples/petstoreWeb/web/account/addresses/Controller.java Wed Nov 2 12:31:57 2005
@@ -32,11 +32,12 @@
import org.apache.beehive.samples.petstore.controls.exceptions.NoSuchAddressException;
import org.apache.beehive.samples.petstore.controls.exceptions.InvalidIdentifierException;
import org.apache.beehive.samples.petstore.forms.AddressForm;
+import org.apache.beehive.samples.petstore.forms.CreateAddressForm;
import org.apache.beehive.samples.petstore.model.Address;
@Jpf.Controller(
sharedFlowRefs = {
- @Jpf.SharedFlowRef(name = "rootSharedFlow", type = webappRoot.SharedFlow.class)
+ @Jpf.SharedFlowRef(name = "rootSharedFlow", type = webappRoot.SharedFlow.class)
},
messageBundles = {@Jpf.MessageBundle(bundlePath = "org.apache.beehive.samples.petstore.resources.account")}
)
@@ -62,8 +63,8 @@
}
)
protected Forward begin() {
-
_sharedFlow.ensureLogin();
+
Forward forward = new Forward("success");
forward.addActionOutput("addresses", _addressControl.getUserAddresses(_sharedFlow.getAccount().getUserId()));
return forward;
@@ -74,27 +75,24 @@
@Jpf.Forward(name = "success", path = "createUpdate.jsp")
}
)
- protected Forward createUpdateAddress() throws InvalidIdentifierException
- {
+ protected Forward createUpdateAddress()
+ throws InvalidIdentifierException {
_sharedFlow.ensureLogin();
// If an addressId is passed in, this is an edit of an existing address
String addressId = getRequest().getParameter("addressId");
Address address;
-
- if (addressId == null)
- {
- // New address
+
+ /* create new address */
+ if (addressId == null) {
address = new Address();
address.setUserId(_sharedFlow.getAccount().getUserId());
- } else {
- // Existing address
- address = _addressControl.getAddress(Integer.parseInt(addressId));
}
+ /* existing address */
+ else address = _addressControl.getAddress(Integer.parseInt(addressId));
_createForm = new CreateAddressForm(address);
- Forward forward = new Forward("success", _createForm);
- return forward;
+ return new Forward("success", _createForm);
}
@Jpf.Action(
@@ -104,20 +102,14 @@
}, validationErrorForward = @Jpf.Forward(name = "failure", navigateTo = Jpf.NavigateTo.currentPage)
)
protected Forward updateAddress(CreateAddressForm form)
- throws InvalidIdentifierException, NoSuchAddressException
- {
+ throws InvalidIdentifierException, NoSuchAddressException {
_sharedFlow.ensureLogin();
Address address = AddressForm.getAddress(form);
if (address.getAddressId() == -1)
- {
- // Add New Address
_addressControl.insertAddress(address);
- } else {
- // Update Existing Address
- _addressControl.updateAddress(address);
- }
+ else _addressControl.updateAddress(address);
return new Forward("success");
}
@@ -127,44 +119,18 @@
@Jpf.Forward(name = "success", action = "begin")
}
)
- protected Forward deleteAddress() throws InvalidIdentifierException, NoSuchAddressException
- {
+ protected Forward deleteAddress()
+ throws InvalidIdentifierException, NoSuchAddressException {
_sharedFlow.ensureLogin();
String addressId = getRequest().getParameter("addressId");
if (addressId == null)
throw new InvalidIdentifierException("AddressId not passed in");
- // Will only delete the address if the user owns it
+ // Will only delete the address if the user owns it
_addressControl.deleteAddress(Integer.parseInt(addressId), _sharedFlow.getAccount().getUserId());
return new Forward("success");
}
- public static class CreateAddressForm
- extends AddressForm {
-
- public CreateAddressForm() {
- super();
- }
-
- public CreateAddressForm(Address address) {
- super(address);
- }
-
- public void setUserId(String userId) {
- getAddress().setUserId(userId);
- }
-
- public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
- ActionErrors errors = new ActionErrors();
- Address address = getAddress();
-
- addErrorIfStringEmpty(errors, "userId", "address.error.userid.required", address.getUserId());
-
- baseValidate(errors, mapping, request);
-
- return errors;
- }
- }
}
Modified: beehive/trunk/samples/petstoreWeb/web/account/create/Controller.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/web/account/create/Controller.java?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/web/account/create/Controller.java (original)
+++ beehive/trunk/samples/petstoreWeb/web/account/create/Controller.java Wed Nov 2 12:31:57 2005
@@ -35,6 +35,7 @@
import org.apache.beehive.samples.petstore.controls.exceptions.AccountAlreadyExistsException;
import org.apache.beehive.samples.petstore.controls.exceptions.UserAlreadyExistsException;
import org.apache.beehive.samples.petstore.forms.AccountForm;
+import org.apache.beehive.samples.petstore.forms.CreateAccountForm;
import org.apache.beehive.samples.petstore.model.Account;
@Jpf.Controller(
@@ -56,6 +57,7 @@
private webappRoot.SharedFlow _sharedFlow = null;
private boolean _isUsernameTaken;
+
private CreateAccountForm _createForm = null;
public boolean isUsernameTaken() {
@@ -65,9 +67,9 @@
@Jpf.Action(
forwards = {
@Jpf.Forward(name = "viewCreateAccount", path = "viewCreateAccount.do")
- }
- )
- protected Forward begin() {
+ }
+ )
+ public Forward begin() {
return new Forward("viewCreateAccount");
}
@@ -84,13 +86,13 @@
})
}
)
- protected Forward viewCreateAccount() {
+ public Forward viewCreateAccount() {
Account account = new Account();
_createForm = new CreateAccountForm(account);
Forward forward = new Forward("success", _createForm);
forward.addActionOutput("categoryNames", _sharedFlow.getCategoryNames());
- forward.addActionOutput("languages", LANGUAGES);
+ forward.addActionOutput("languages", getLanguages());
return forward;
}
@@ -103,10 +105,12 @@
},
validationErrorForward = @Jpf.Forward(name = "failure", navigateTo = Jpf.NavigateTo.currentPage)
)
- protected Forward createAccount(CreateAccountForm form)
+ public Forward createAccount(CreateAccountForm form)
throws AccountAlreadyExistsException, InvalidIdentifierException, UserAlreadyExistsException, NoSuchAccountException {
+
// ensure unique user name
_isUsernameTaken = false;
+
if(_accountControl.checkAccountExists(form.getUserId())) {
_isUsernameTaken = true;
return new Forward("failure");
@@ -118,57 +122,5 @@
_sharedFlow.updateAccount(userAccount);
return new Forward("shop");
- }
-
- public static class CreateAccountForm
- extends AccountForm {
-
- private String _repeatedPassword;
-
- public CreateAccountForm() {
- super();
- }
-
- public CreateAccountForm(Account account) {
- super(account);
- }
-
- public void setUserId(String userId) {
- getAccount().setUserId(userId);
- }
-
- public String getPassword() {
- return getAccount().getPassword();
- }
-
- public void setPassword(String password) {
- getAccount().setPassword(password);
- }
-
- public String getRepeatedPassword() {
- return _repeatedPassword;
- }
-
- public void setRepeatedPassword(String repeatedPassword) {
- _repeatedPassword = repeatedPassword;
- }
-
- public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
- ActionErrors errors = new ActionErrors();
- Account account = getAccount();
- account.setStatus("OK");
-
- addErrorIfStringEmpty(errors, "userId", "account.error.userid.required", account.getUserId());
-
- if(account.getPassword() == null ||
- account.getPassword().length() < 1 ||
- !account.getPassword().equals(getRepeatedPassword())) {
- errors.add("repeatedPassword", new ActionError("account.error.password.missing"));
- }
-
- baseValidate(errors, mapping, request);
-
- return errors;
- }
}
}
Modified: beehive/trunk/samples/petstoreWeb/web/account/create/create.jsp
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/web/account/create/create.jsp?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/web/account/create/create.jsp (original)
+++ beehive/trunk/samples/petstoreWeb/web/account/create/create.jsp Wed Nov 2 12:31:57 2005
@@ -26,7 +26,6 @@
<netui-data:declarePageInput name="languages" type="java.lang.String[]"/>
<netui-data:declareBundle bundlePath="org.apache.beehive.samples.petstore.resources.view" name="view"/>
-
<netui-template:template templatePage="/site/template.jsp">
<netui-template:setAttribute name="title" value="${bundle.view.createAccountLabel}" />
Modified: beehive/trunk/samples/petstoreWeb/web/account/edit/Controller.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/web/account/edit/Controller.java?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/web/account/edit/Controller.java (original)
+++ beehive/trunk/samples/petstoreWeb/web/account/edit/Controller.java Wed Nov 2 12:31:57 2005
@@ -30,6 +30,7 @@
import org.apache.beehive.samples.petstore.controls.exceptions.NoSuchAccountException;
import org.apache.beehive.samples.petstore.controls.exceptions.NoSuchUserException;
import org.apache.beehive.samples.petstore.forms.AccountForm;
+import org.apache.beehive.samples.petstore.forms.UpdateAccountForm;
import org.apache.beehive.samples.petstore.controller.AccountController;
import org.apache.beehive.controls.api.bean.Control;
@@ -80,7 +81,7 @@
Forward forward = new Forward("update");
forward.addOutputForm(_updateForm);
- forward.addActionOutput("languages", LANGUAGES);
+ forward.addActionOutput("languages", getLanguages());
forward.addActionOutput("categoryNames", _sharedFlow.getCategoryNames());
return forward;
}
@@ -133,40 +134,4 @@
/**
*
*/
- public static class UpdateAccountForm
- extends AccountForm {
-
- private String _newPassword;
- private String _repeatedPassword;
-
- public UpdateAccountForm() {
- super();
- }
-
- public UpdateAccountForm(Account account) {
- super(account);
- }
-
- public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
- ActionErrors errors = new ActionErrors();
- baseValidate(errors, mapping, request);
- return errors;
- }
-
- public String getNewPassword() {
- return _newPassword;
- }
-
- public void setNewPassword(String value) {
- _newPassword = value;
- }
-
- public String getRepeatedPassword() {
- return _repeatedPassword;
- }
-
- public void setRepeatedPassword(String value) {
- _repeatedPassword = value;
- }
- }
}
Modified: beehive/trunk/samples/petstoreWeb/web/auth/Controller.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/web/auth/Controller.java?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/web/auth/Controller.java (original)
+++ beehive/trunk/samples/petstoreWeb/web/auth/Controller.java Wed Nov 2 12:31:57 2005
@@ -18,13 +18,13 @@
package auth;
import org.apache.beehive.netui.pageflow.annotations.Jpf;
-import org.apache.beehive.netui.pageflow.FormData;
import org.apache.beehive.netui.pageflow.Forward;
import org.apache.beehive.netui.pageflow.PageFlowController;
import org.apache.beehive.samples.petstore.controls.exceptions.InvalidIdentifierException;
import org.apache.beehive.samples.petstore.controls.exceptions.NoSuchAccountException;
import org.apache.beehive.samples.petstore.forms.ReturnToForm;
+import org.apache.beehive.samples.petstore.forms.SecurityCheckForm;
@Jpf.Controller(
nested = true,
@@ -41,7 +41,7 @@
private ReturnToForm _initForm;
@Jpf.Action(
- forwards = {
+ forwards = {
@Jpf.Forward(name = "success", path = "login.jsp")
}
)
@@ -51,7 +51,7 @@
}
@Jpf.Action(
- forwards = {
+ forwards = {
@Jpf.Forward(name = "success", path = "login.jsp")
}
)
@@ -60,25 +60,25 @@
}
@Jpf.Action(
- forwards = {
+ forwards = {
@Jpf.Forward(name = "failure", path = "loginError.jsp"),
@Jpf.Forward(
- name = "success",
- returnAction = "rootSharedFlow.loginDone",
+ name = "success",
+ returnAction = "rootSharedFlow.loginDone",
outputFormBean = "_initForm"
)
}
)
- protected Forward securityCheck(SecurityCheckForm form)
- throws NoSuchAccountException, InvalidIdentifierException
- {
- try
- {
- _sharedFlow.handleLogin(form.getj_username());
- } catch (NoSuchAccountException e)
- {
- // ignore during login
- }
+ protected Forward securityCheck(SecurityCheckForm form)
+ throws NoSuchAccountException, InvalidIdentifierException
+ {
+ try
+ {
+ _sharedFlow.handleLogin(form.getj_username());
+ }
+ catch (NoSuchAccountException e)
+ {
+ }
if(!_sharedFlow.isUserLoggedIn())
return new Forward("failure");
@@ -94,28 +94,4 @@
_sharedFlow.handleLogout();
return new Forward("success");
}
-
- public static class SecurityCheckForm
- extends FormData {
-
- private String _j_username;
- private String _j_password;
-
- public void setj_password(String j_password) {
- _j_password = j_password;
- }
-
- public String getj_password() {
- return _j_password;
- }
-
- public void setj_username(String j_username) {
- _j_username = j_username;
- }
-
- public String getj_username() {
- return _j_username;
- }
- }
-
}
Modified: beehive/trunk/samples/petstoreWeb/web/checkout/Controller.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/web/checkout/Controller.java?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/web/checkout/Controller.java (original)
+++ beehive/trunk/samples/petstoreWeb/web/checkout/Controller.java Wed Nov 2 12:31:57 2005
@@ -64,8 +64,7 @@
@Jpf.Action(
forwards={@Jpf.Forward(name="success", path="viewCart.jsp")}
)
- public Forward begin()
- {
+ public Forward begin() {
return new Forward("success");
}
@@ -73,8 +72,7 @@
forwards={@Jpf.Forward(name="success", action="viewCreateOrder")
}
)
- protected Forward createNewOrder()
- {
+ protected Forward createNewOrder() {
_sharedFlow.ensureLogin();
_sharedFlow.getAccount().setStatus("checking_out");
@@ -103,8 +101,8 @@
)
}
)
- protected Forward viewCreateOrder()
- {
+ protected Forward viewCreateOrder() {
+
_sharedFlow.ensureLogin();
Forward forward = new Forward("success");
@@ -121,8 +119,7 @@
@Jpf.Forward(name="done", returnAction="checkoutDone")
}
)
- public Forward done()
- {
+ public Forward done() {
return new Forward("done");
}
@@ -147,8 +144,8 @@
},
validationErrorForward=@Jpf.Forward(name="failure", navigateTo=Jpf.NavigateTo.currentPage)
)
- protected Forward viewConfirm(CheckoutForm orderForm) throws InvalidIdentifierException
- {
+ protected Forward viewConfirm(CheckoutForm orderForm)
+ throws InvalidIdentifierException {
_sharedFlow.ensureLogin();
Forward f = new Forward("confirm");
@@ -163,8 +160,8 @@
forwards={@Jpf.Forward(name="success", action="viewOrder")}
)
protected Forward confirm()
- throws NoSuchOrderException, InvalidIdentifierException, OrderAlreadyExistsException
- {
+ throws NoSuchOrderException, InvalidIdentifierException, OrderAlreadyExistsException {
+
_sharedFlow.ensureLogin();
// Write the order to the DB
@@ -196,8 +193,8 @@
})
}
)
- protected Forward viewOrder() throws NoSuchOrderException, InvalidIdentifierException
- {
+ public Forward viewOrder()
+ throws NoSuchOrderException, InvalidIdentifierException {
_sharedFlow.ensureLogin();
int orderId = -1;
@@ -218,8 +215,8 @@
if (bNew)
_order.setStatus("new");
- Address billingAddress = new Address();
- Address shippingAddress = new Address();
+ Address billingAddress;
+ Address shippingAddress;
billingAddress = _addressControl.getAddress(_order.getBillingAddress());
shippingAddress = _addressControl.getAddress(_order.getShippingAddress());
Modified: beehive/trunk/samples/petstoreWeb/web/index.jsp
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/web/index.jsp?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/web/index.jsp (original)
+++ beehive/trunk/samples/petstoreWeb/web/index.jsp Wed Nov 2 12:31:57 2005
@@ -32,7 +32,7 @@
<netui-template:section name="body">
- <!-- Turn off the left nav -->
+ <%-- Turn off the left nav --%>
<style> #leftnav {display: none;} </style>
<table cellSpacing="50" width="100%">
Modified: beehive/trunk/samples/petstoreWeb/web/search/index.jsp
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/web/search/index.jsp?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/web/search/index.jsp (original)
+++ beehive/trunk/samples/petstoreWeb/web/search/index.jsp Wed Nov 2 12:31:57 2005
@@ -28,14 +28,12 @@
<netui-template:section name="leftnav">
</netui-template:section>
-
<netui-template:section name="body">
-
- <netui:span styleClass="boldlabel" value="${bundle.search.searchResultsLabel}"/>
+ <netui:span styleClass="boldlabel" value="${bundle.search.searchResultsLabel}"/>
- <netui-data:repeater dataSource="pageInput.searchResults" defaultText="<br/><br/>${bundle.search.noSearchResults}<br/><br/>">
- <netui-data:repeaterHeader>
- <table class="tableborder" cellpadding="0" cellspacing="1">
+ <netui-data:repeater dataSource="pageInput.searchResults" defaultText="<br/><br/>${bundle.search.noSearchResults}<br/><br/>">
+ <netui-data:repeaterHeader>
+ <table class="tableborder" cellpadding="0" cellspacing="1">
<tr class="rowgrey">
<td> </td>
<td><b>${bundle.view.productIdLabel}</b></td>
@@ -43,32 +41,32 @@
<td><b>${bundle.view.descriptionLabel}</b></td>
</tr>
</netui-data:repeaterHeader>
- <netui-data:repeaterItem>
- <tr class="rowltgrey">
- <td>
- <netui:imageAnchor action="rootSharedFlow.globalViewProductById"border="0" src="${pageContext.request.contextPath}/images/${container.item.image}">
- <netui:parameter name="productId" value="${container.item.productId}"/>
- </netui:imageAnchor>
- </td>
- <td>
- <b>
- <netui:anchor action="rootSharedFlow.globalViewProductById">
- <netui:parameter name="productId" value="${container.item.productId}"/>
- <font color="black"><netui:span value="${container.item.productId}"/></font>
- </netui:anchor>
- </b>
- </td>
- <td>
- <netui:span value="${container.item.name}"/>
- </td>
- <td>
- <netui:span value="${container.item.description}"/>
- </td>
- </tr>
- </netui-data:repeaterItem>
- <netui-data:repeaterFooter>
- </table>
- </netui-data:repeaterFooter>
- </netui-data:repeater>
+ <netui-data:repeaterItem>
+ <tr class="rowltgrey">
+ <td>
+ <netui:imageAnchor action="rootSharedFlow.globalViewProductById"border="0" src="${pageContext.request.contextPath}/images/${container.item.image}">
+ <netui:parameter name="productId" value="${container.item.productId}"/>
+ </netui:imageAnchor>
+ </td>
+ <td>
+ <b>
+ <netui:anchor action="rootSharedFlow.globalViewProductById">
+ <netui:parameter name="productId" value="${container.item.productId}"/>
+ <font color="black"><netui:span value="${container.item.productId}"/></font>
+ </netui:anchor>
+ </b>
+ </td>
+ <td>
+ <netui:span value="${container.item.name}"/>
+ </td>
+ <td>
+ <netui:span value="${container.item.description}"/>
+ </td>
+ </tr>
+ </netui-data:repeaterItem>
+ <netui-data:repeaterFooter>
+ </table>
+ </netui-data:repeaterFooter>
+ </netui-data:repeater>
</netui-template:section>
</netui-template:template>
Modified: beehive/trunk/samples/petstoreWeb/web/shop/Controller.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/web/shop/Controller.java?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/web/shop/Controller.java (original)
+++ beehive/trunk/samples/petstoreWeb/web/shop/Controller.java Wed Nov 2 12:31:57 2005
@@ -17,11 +17,6 @@
*/
package shop;
-
-import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.beehive.netui.pageflow.FormData;
import org.apache.beehive.netui.pageflow.Forward;
import org.apache.beehive.netui.pageflow.PageFlowController;
import org.apache.beehive.netui.pageflow.annotations.Jpf;
@@ -31,18 +26,13 @@
import org.apache.beehive.samples.petstore.model.Cart;
import org.apache.beehive.samples.petstore.model.Category;
import org.apache.beehive.samples.petstore.model.Item;
-import org.apache.beehive.samples.petstore.model.LineItem;
import org.apache.beehive.samples.petstore.model.Product;
+import org.apache.beehive.samples.petstore.forms.CartForm;
import org.apache.beehive.controls.api.bean.Control;
-import org.apache.struts.action.ActionError;
-import org.apache.struts.action.ActionErrors;
-import org.apache.struts.action.ActionMapping;
-
@Jpf.Controller(
forwards = {
- @Jpf.Forward(name = "cart", path = "cart.jsp"),
- @Jpf.Forward(name = "viewCart", path = "viewCart.do")
+ @Jpf.Forward(name = "cart", path = "cart.jsp")
},
sharedFlowRefs={
@Jpf.SharedFlowRef(name="rootSharedFlow", type=webappRoot.SharedFlow.class)
@@ -61,18 +51,19 @@
private webappRoot.SharedFlow _sharedFlow = null;
/* todo: this should be shared for all users */
- private Category[] _categories; // the list of categories
+ /* categories */
+ private Category[] _categories;
- private Category _currentCategory; // the current category being viewed
- private Product _currentProduct; // the current product being viewed
- private Item _currentItem; // the current item being viewed
+ /* current category */
+ private Category _currentCategory;
- private CartForm _cartForm;
+ /* current product */
+ private Product _currentProduct;
- protected void onCreate() {
- _cartForm = new CartForm();
- _cartForm.setCart(_sharedFlow.getCart());
- }
+ /* current item */
+ private Item _currentItem;
+
+ private CartForm _cartForm;
@Jpf.Action(
forwards = {
@@ -84,7 +75,7 @@
})
}
)
- protected Forward begin() {
+ public Forward begin() {
if(_categories == null)
_categories = _catalogControl.getCategoryList();
@@ -104,7 +95,8 @@
})
}
)
- protected Forward viewCategory() throws InvalidIdentifierException {
+ public Forward viewCategory()
+ throws InvalidIdentifierException {
String categoryId = getRequest().getParameter("catId");
if(categoryId == null || categoryId.equals(""))
@@ -132,7 +124,8 @@
})
}
)
- protected Forward viewProduct() throws InvalidIdentifierException {
+ public Forward viewProduct()
+ throws InvalidIdentifierException {
String productId = getRequest().getParameter("productId");
if(productId == null || productId.equals(""))
@@ -160,7 +153,8 @@
})
}
)
- protected Forward viewItem() throws InvalidIdentifierException {
+ public Forward viewItem()
+ throws InvalidIdentifierException {
String itemId = getRequest().getParameter("itemId");
if(itemId == null || itemId.equals(""))
@@ -175,113 +169,74 @@
return f;
}
- @Jpf.Action(useFormBean = "_cartForm",
- forwards = {
- @Jpf.Forward(name = "success",
- path = "cart.jsp",
- actionOutputs = {
- @Jpf.ActionOutput(name = "myList",
- type = org.apache.beehive.samples.petstore.model.Product[].class,
- required = false)
- }),
- @Jpf.Forward(name="cart", path="cart.jsp")
- })
- protected Forward addItemToCart(CartForm form) throws InvalidIdentifierException {
- Cart cart = form.getCart();
- if (cart.containsItemId(form.getWorkingItemId()))
- {
- cart.incrementQuantityByItemId(form.getWorkingItemId());
- }
- else
- {
- Item toAddItem = _catalogControl.getItem(form.getWorkingItemId());
+ @Jpf.Action()
+ public Forward addItemToCart()
+ throws InvalidIdentifierException {
+
+ String workingItemId = lookupCurrentItemId();
+
+ if(workingItemId == null)
+ throw new InvalidIdentifierException("Could not find working item identifier");
+
+ Cart cart = lookupCart();
+ if (cart.containsItemId(workingItemId))
+ cart.incrementQuantityByItemId(workingItemId);
+ else {
+ Item toAddItem = _catalogControl.getItem(workingItemId);
if (toAddItem != null)
- {
- //toAddItem.setProduct(_currentProduct);
cart.addItem(toAddItem);
- }
- /* todo: error handling path */
}
- return new Forward("cart", "product", _currentProduct);
+ _cartForm = new CartForm();
+ _cartForm.setCart(lookupCart());
+ Forward forward = setupCartForward();
+ forward.addActionOutput("product", _currentProduct);
+ return forward;
}
- @Jpf.Action(useFormBean = "_cartForm", forwards={@Jpf.Forward(name="cart", path="cart.jsp")})
- protected Forward viewCart(CartForm form) {
- return new Forward("cart");
- }
-
- @Jpf.Action(useFormBean = "_cartForm",
- forwards = {
- @Jpf.Forward(name = "cart",
- path = "cart.jsp",
- actionOutputs = {
- @Jpf.ActionOutput(name = "myList",
- type = org.apache.beehive.samples.petstore.model.Product[].class,
- required = false)
- })
- })
- protected Forward updateCartQuantities(CartForm form) {
- return new Forward("cart", "product", _currentProduct);
- }
-
- @Jpf.Action(useFormBean = "_cartForm",
- forwards = {
- @Jpf.Forward(name = "success",
- path = "cart.jsp",
- actionOutputs = {
- @Jpf.ActionOutput(name = "myList",
- type = org.apache.beehive.samples.petstore.model.Product[].class,
- required = false)
- }),
- @Jpf.Forward(name="cart", path="cart.jsp")
- })
- protected Forward removeItemFromCart(CartForm form) {
- if(_cartForm.getCart().containsItemId(form.getWorkingItemId()))
- _cartForm.getCart().removeItemById(form.getWorkingItemId());
-
- return new Forward("cart", "product", _currentProduct);
+ @Jpf.Action
+ public Forward viewCart() {
+ _cartForm = new CartForm();
+ _cartForm.setCart(lookupCart());
+ return setupCartForward();
}
- public static class CartForm
- extends FormData {
-
- private String _workingItemId;
- private Cart _cart;
-
- public void setCart(Cart cart) {
- _cart = cart;
- }
-
- public Cart getCart() {
- return _cart;
- }
-
- public void setWorkingItemId(String workingItemId) {
- _workingItemId = workingItemId;
- }
+ /* todo: need to get line-by-line updates working again here */
+ @Jpf.Action(useFormBean="_cartForm")
+ public Forward updateCartQuantities(CartForm cartForm) {
+ Forward forward = setupCartForward();
+ forward.addActionOutput("product", _currentProduct);
+ return forward;
+ }
- public String getWorkingItemId() {
- return _workingItemId;
- }
+ @Jpf.Action
+ public Forward removeItemFromCart() {
+ String itemId = lookupCurrentItemId();
+
+ Cart cart = lookupCart();
+ if(cart.containsItemId(itemId))
+ cart.removeItemById(itemId);
- public void reset(ActionMapping mapping, HttpServletRequest request) {
- super.reset(mapping, request);
+ Forward forward = setupCartForward();
+ forward.addActionOutput("product", _currentProduct);
+ return forward;
+ }
- _workingItemId = null;
- }
+ private Forward setupCartForward() {
+ CartForm form = new CartForm();
+ form.setCart(lookupCart());
- public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
- ActionErrors errors = new ActionErrors();
+ Forward forward = new Forward("cart");
+ forward.addOutputForm(form);
+ return forward;
+ }
- List<LineItem> items = getCart().getLineItems();
- if(items != null && items.size() > 0) {
- for(int i = 0; i < items.size(); i++) {
- errors.add("invalidQuantity" + i, new ActionError("order.error.invalidQuantity"));
- }
- }
+ private String lookupCurrentItemId() {
+ String itemId = getRequest().getParameter("workingItemId");
+ return itemId;
+ }
- return errors;
- }
+ private Cart lookupCart() {
+ return _sharedFlow.getCart();
}
}
Modified: beehive/trunk/samples/petstoreWeb/web/webappRoot/SharedFlow.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/petstoreWeb/web/webappRoot/SharedFlow.java?rev=330352&r1=330351&r2=330352&view=diff
==============================================================================
--- beehive/trunk/samples/petstoreWeb/web/webappRoot/SharedFlow.java (original)
+++ beehive/trunk/samples/petstoreWeb/web/webappRoot/SharedFlow.java Wed Nov 2 12:31:57 2005
@@ -210,7 +210,7 @@
@Jpf.Forward(name="errorPage", path="/resources/beehive/version1/jsps/error.jsp")
}
)
- protected Forward handleException(Exception ex, String actionName, String message, Object form) {
+ public Forward handleException(Exception ex, String actionName, String message, Object form) {
System.err.print("[" + getRequest().getContextPath() + "] ");
System.err.println("Unhandled exception caught in SharedFlow.jpfs:");
ex.printStackTrace();
@@ -222,7 +222,7 @@
@Jpf.Forward(name="errorPage", path="/resources/beehive/version1/jsps/error.jsp")
}
)
- protected Forward handleDataStoreException(DataStoreException ex, String actionName, String message, Object form) {
+ public Forward handleDataStoreException(DataStoreException ex, String actionName, String message, Object form) {
System.err.print("[" + getRequest().getContextPath() + "] ");
System.err.println("DataStore exception caught in SharedFlow.jpfs:");
ex.printStackTrace();
@@ -232,7 +232,7 @@
@Jpf.ExceptionHandler(
forwards={@Jpf.Forward(name="auth", path="/auth/Controller.jpf")}
)
- protected Forward handleNotLoggedInException(NotLoggedInException ex, String actionName, String message, Object form) {
+ public Forward handleNotLoggedInException(NotLoggedInException ex, String actionName, String message, Object form) {
ReturnToForm initForm = new ReturnToForm(true);
return new Forward("auth", initForm);
}