/*
* Copyright 2006 - 2012 Hannes Holtzhausen
*
* 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.
*/
/*
* $Id: ProductTypeFormAction.java,v 1.2 2007/11/01 22:53:15 hannes Exp $
*
* Description:
*
*/
package app.web;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import toolbox.web.*;
import toolbox.services.*;
import toolbox.web.validation.*;
import app.beans.*;
import app.services.*;
/**
* Handles all product type form requests.
*
* @author Hannes Holtzhausen
*/
public class ProductTypeFormAction extends BaseWebAction implements WebAction
{
/**
* Default constructor
*/
public ProductTypeFormAction()
{
}
/**
* Receive requests to add or update product type information and attempts
* to perform the operation.
*
* @param request HTTP request.
* @param response HTTP response.
* @param context Web application context.
*
* @throws ServletException
* @throws IOException
*/
public void execute(HttpServletRequest request,
HttpServletResponse response,
ServletContext context) throws ServletException,
IOException
{
ProductService service = null;
try
{
ServiceRegistry registry =
ServiceRegistryFactory.getRegistry("beansdemo");
service =
(ProductService)registry.getService(registry.getProperty("default_svc"),
ProductService.class);
String msg = null;
String action = request.getParameter("type_action");
Map map = getValidator().validate("type",request);
ProductType type = ProductType.create(map);
if(action.equals("add"))
{
service.addProductType(type);
msg = getResourceString("generic.addmessage",
new Object[] { type.getType() },
request.getLocale());
}
else
{
service.updateProductType(type);
msg = getResourceString("generic.updatemessage",
new Object[] { type.getType() },
request.getLocale());
}
request.setAttribute("message",msg);
dispatch(request,response,context,getSuccessTemplate());
}
catch (ValidationException ve)
{
request.setAttribute("errors",ve.getMessages());
dispatch(request,response,context,getFailureTemplate());
}
catch (ServiceException ae)
{
request.setAttribute("message",ae.getMessage());
dispatch(request,response,context,getFailureTemplate());
}
catch (Exception e)
{
request.setAttribute("message",e.getMessage());
dispatch(request,response,context,getFailureTemplate());
}
}
}
|