📄 changeshippingaddressaction.java
字号:
/*
* @author : Sujatha
* @Version : 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the File : ChangeShippingAddressAction.java
* Creation/Modification History :
*
* Sujatha 14-Jan-2003 Created
*
*/
package oracle.otnsamples.vsm.actions.orders;
// IO and servlet API
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import oracle.otnsamples.util.MessageCache;
import oracle.otnsamples.util.ServiceLocator;
import oracle.otnsamples.vsm.actions.forms.ShippingAddressForm;
import oracle.otnsamples.vsm.services.MallNavigation;
import oracle.otnsamples.vsm.services.MallNavigationHome;
import oracle.otnsamples.vsm.services.OrderException;
import oracle.otnsamples.vsm.services.OrderManagement;
import oracle.otnsamples.vsm.services.OrderManagementHome;
import oracle.otnsamples.vsm.services.ProfileManagement;
import oracle.otnsamples.vsm.services.ProfileManagementHome;
import oracle.otnsamples.vsm.services.data.Address;
import oracle.otnsamples.vsm.services.data.Country;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
/**
* This Action class is used to change the shipping address for a given order.
*
* @author Sujatha
* @version 1.0
*/
public class ChangeShippingAddressAction extends DispatchAction {
/**
* This is the action called from the Struts framework to get the list of
* countries to be displayed in the change address form
*
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
*/
public ActionForward displayForm(
ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
ProfileManagementHome profileHome = null;
ProfileManagement profileBean = null;
MallNavigationHome navigationHome = null;
MallNavigation navigation = null;
OrderManagementHome orderHome = null;
OrderManagement orderBean = null;
ShippingAddressForm address = null;
ActionForward forward = mapping.findForward("display");
try {
profileHome =
(ProfileManagementHome) ServiceLocator.getLocator().getService("ProfileManagement");
profileBean = profileHome.create();
// Get the list of countries and set the same in request scope
navigationHome =
(MallNavigationHome) ServiceLocator.getLocator().getService("MallNavigation");
navigation = navigationHome.create();
Country[] countries = navigation.getCountries();
request.setAttribute("countries", countries);
// Fetch the current shipping address and set the same in request scope
orderHome =
(OrderManagementHome) ServiceLocator.getLocator().getService("OrderManagement");
orderBean = orderHome.create();
String orderID = request.getParameter("orderID");
address = new ShippingAddressForm(orderBean.getShippingAddress(orderID));
request.setAttribute("address", address);
request.setAttribute("orderID", orderID);
} catch(OrderException ex) {
servlet.log("DisplayAddressFormError", ex);
request.setAttribute(
"message",
MessageCache.getMessage(
ex.getMessageCode(),
getLocale(request)));
return mapping.findForward("display");
} catch(Exception ex) {
servlet.log("DisplayAddressFormError", ex);
ActionErrors errors = new ActionErrors();
errors.add(
"OrderError", new ActionError("common.error", ex.getMessage()));
saveErrors(request, errors);
return mapping.findForward("error");
} finally {
try {
if(profileBean != null) {
profileBean.remove();
}
if(orderBean != null) {
orderBean.remove();
}
} catch(Exception ex) {
}
}
return forward;
}
/**
* This is the action called from the Struts framework to change the
* shipping address of an order
*
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
*/
public ActionForward changeAddress(
ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
OrderManagementHome orderHome = null;
OrderManagement orderBean = null;
ShippingAddressForm address = (ShippingAddressForm) form;
ActionForward forward = mapping.findForward("success");
try {
orderHome =
(OrderManagementHome) ServiceLocator.getLocator().getService("OrderManagement");
orderBean = orderHome.create();
orderBean.changeShippingAddress(
new Address(
address.getAddress(),
address.getCity(),
address.getState(),
address.getCountry(),
Integer.parseInt(address.getZip()),
address.getPhone()),
request.getParameter("orderID"));
request.setAttribute(
"message",
MessageCache.getMessage(
"message.addresschange.success",
getLocale(request)));
} catch(OrderException ex) {
servlet.log("ChangeAddressError", ex);
request.setAttribute(
"message",
MessageCache.getMessage(
ex.getMessageCode(),
getLocale(request)));
return mapping.findForward("display");
} catch(Exception ex) {
servlet.log("ChangeAddressError", ex);
ActionErrors errors = new ActionErrors();
errors.add(
"OrderError", new ActionError("common.error", ex.getMessage()));
saveErrors(request, errors);
return mapping.findForward("error");
} finally {
try {
if(orderBean != null) {
orderBean.remove();
}
} catch(Exception ex) {
}
}
return forward;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -