DisplayCustomerAction.java

package com.dotj.web.struts; 
 
import java.util.Locale; 
import javax.servlet.http.HttpSession; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
import org.apache.commons.logging.Log; 
import org.apache.commons.logging.LogFactory; 
import org.apache.struts.action.Action; 
import org.apache.struts.action.ActionForm; 
import org.apache.struts.action.ActionForward; 
import org.apache.struts.action.ActionMapping; 
import org.apache.struts.util.MessageResources; 
import com.dotj.io.DataSet; 
 
 
public final class DisplayCustomerAction extends Action { 
    /** 
     * The <code>Log</code> instance for this application. 
     */ 
    protected static Log log = 
            LogFactory.getLog(DisplayCustomerAction.class); 
 
 
    // --------------------------------------------------------- Public Methods
/** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed. * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * @throws Exception if the application business logic throws * an exception */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need Locale locale = getLocale(request); MessageResources messages = getResources(request); HttpSession session = request.getSession(); // Set a transactional control token to prevent double posting if (log.isTraceEnabled()) { log.trace(" Setting transactional control token"); } saveToken(request); String sql = "SELECT * FROM customer " + "WHERE Id = 1"; DataSet ds = JDBCUtil.executeQuery(servlet.getServletContext(), sql); if (form == null) { form = new CustomerForm(); } CustomerForm customerForm = (CustomerForm) form; if (ds != null && ds.next()) { customerForm.setId(ds.getLong("id")); customerForm.setLastName(ds.getString("lastName")); customerForm.setFirstName(ds.getString("firstName")); customerForm.setCity(ds.getString("city")); customerForm.setState(ds.getString("state")); customerForm.setZipCode(ds.getString("zip")); customerForm.setCountry(ds.getString("country")); customerForm.setGender(ds.getString("gender")); customerForm.setEmployed(ds.getString("employed")); customerForm.setComments(ds.getString("comments")); customerForm.setApproved(ds.getString("approved")); } request.setAttribute(mapping.getAttribute(), customerForm); // Forward control to the edit user registration page if (log.isTraceEnabled()) { log.trace(" Forwarding to 'success' page"); } return (mapping.findForward("success")); } }