public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
String action;
HttpSession session;
ActionErrors errors = new ActionErrors();
try
{
session = request.getSession();
// fetch action from form
action = ((AddressForm)form).getAction();
servlet.log("[DEBUG] AddressAction at perform(): Action ist " + action);
// Determine what to do
if ( action.equals("edit") )
{
// forward to edit formular
return (mapping.findForward("editAddress"));
}
else if (action.equals("save"))
{
// check if an address bean exits already
AddressBean bean = (AddressBean)session.getAttribute("address");
if (bean == null)
{
bean = new AddressBean();
session.setAttribute("address", bean);
}
// update bean with the new values submitted
bean.setFirstname( ((AddressForm)form).getFirstname() );
bean.setLastname( ((AddressForm)form).getLastname() );
bean.setStreet( ((AddressForm)form).getStreet() );
bean.setZip( ((AddressForm)form).getZip() );
bean.setCity( ((AddressForm)form).getCity() );
bean.setCountry( ((AddressForm)form).getCountry() );
bean.setLanguages( ((AddressForm)form).getLanguages() );
// forward to list
return (mapping.findForward("showAddress"));
}
else
{
String locale = ((AddressForm)form).getLocale();
if (locale.equals("Deutsch"))
session.setAttribute(Globals.LOCALE_KEY, new Locale("de", ""));
else
session.setAttribute(Globals.LOCALE_KEY, new Locale("en", ""));
// forward to edit formular
return (mapping.findForward("showAddress"));
}
}
catch (Exception e)
{
//errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("lo053"));
servlet.log("[ERROR] TskAction at final catch: " + e.getMessage());
e.printStackTrace();
}
// Default if everthing else fails
return (mapping.findForward("showAddress"));
}
|