A Struts Tool for Previewing Forms and Generating Beans
by Andy W.K.Yuen

Listing One
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD 
                                Struts Configuration 1.1//EN"
                               "http://jakarta.apache.org/struts/
                                dtds/struts-config_1_1.dtd">
<struts-config>
 <data-sources/>
 <form-beans>
  <form-bean name="FileUploadForm" type="application.FileUploadForm"/>
  <form-bean name="UserPageForm" type="application.UserPageForm"/>
 </form-beans>
 <global-exceptions/>
 <global-forwards>
  <forward name="upload" path="/pages/fileupload.jsp"/>
  <forward name="view" path="/pages/userpage.jsp"/>
 </global-forwards>
 <action-mappings>
  <action name="FileUploadForm" path="/FileUpload" scope="request"
   type="application.FileUploadAction" validate="no">
   <forward name="viewsource" path="/pages/viewsource.jsp"/>
  </action>
  <action name="UserPageForm" path="/UserPage" scope="request"
   type="application.UserPageAction" validate="no"/>
 </action-mappings>
 <controller/>
 <message-resources null="false" parameter="application"/>
</struts-config>

Listing Two
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html locale="true">
<head>
    <title>Shopping Cart Content</title>
</head>
<body>
<h3>Shopping Cart Content</h3>
<table border="1" align="center">
<tr bgcolor="#808080">
<th>Item Id</th><th>Item Description</th><th>Unit Cost</th>
                                      <th>Quantity</th><th>Total Cost</th>

<% for (int i = 0; i < 5; i++) { %>
<tr>
    <td><%= i %></td>
    <td>Widget <%= i %></td>
    <td><%= 10.95 + i * 10 %></td>
    <td>
        <html:form action="Order.do">
        <html:hidden property="itemId" value="Id<%= i %>" />
        <html:text property="quantity" value="1" />
        <html:submit value="Update Quantity" />
        </html:form>
    </td>
    <td><%= 10.95 + i * 10 %></td>
</tr>
<% } %>
</table>
<html:form action="CheckOut.do">
<center>
<html:submit value="Checkout" />
</center>
</html:form>
</body>
</html:html>


Listing Three
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html locale="true">
<head>
    <title>Shopping Cart Content</title>
</head>
<body>
<h3>Shopping Cart Content</h3>
<table border="1" align="center">
<tr bgcolor="#808080">
<th>Item Id</th><th>Item Description</th><th>Unit Cost</th>
                                      <th>Quantity</th><th>Total Cost</th>
<% for (int i = 0; i < 5; i++) { %>
<tr>
    <td><%= i %></td>
    <td>Widget <%= i %></td>
    <td><%= 10.95 + i * 10 %></td>
    <td>
        <html:form action="UserPage.do">
        <html:hidden property="itemId" value="Id<%= i %>" />
        <html:text property="quantity" value="1" />
        <html:submit value="Update Quantity" />
        </html:form>
    </td>
    <td><%= 10.95 + i * 10 %></td>
</tr>
<% } %>
</table>
<html:form action="UserPage.do">
<center>
<html:submit value="Checkout" />
</center>
</html:form>
</body>
</html:html>

Listing Four
// ActionForm class: OrderForm.java
// Generated by beanGenerator on: Sun Aug 10 12:29:14 EST 2003
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

public class OrderForm extends ActionForm {
private String itemId = "";
public String getItemId() { return itemId; }
public void setItemId(String itemId) { this.itemId = itemId; }
private String quantity = "1";
public String getQuantity() { return quantity; }
public void setQuantity(String quantity) { this.quantity = quantity; }
public void reset(ActionMapping actionMapping, HttpServletRequest request) {
    // TODO: Write method body
        quantity = "1";
        itemId = "";
}
public ActionErrors validate(ActionMapping actionMapping, 
                                               HttpServletRequest request) {
    // TODO: Write method body
    throw new UnsupportedOperationException("Method not implemented");
}
}
// ActionForm class: CheckOutForm.java
// Generated by beanGenerator on: Sun Aug 10 12:29:14 EST 2003
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

public class CheckOutForm extends ActionForm {
public void reset(ActionMapping actionMapping, HttpServletRequest request) {
    // TODO: Write method body
}
public ActionErrors validate(ActionMapping actionMapping, 
                                                HttpServletRequest request) {
    // TODO: Write method body
    throw new UnsupportedOperationException("Method not implemented");
}
}

Listing Five
package application;
// ActionForm class: UserPageForm.java
// Generated by beanGenerator on: Sun Aug 10 12:29:14 EST 2003
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

public class UserPageForm extends ActionForm {
private String itemId = "";
public String getItemId() { return itemId; }
public void setItemId(String itemId) { this.itemId = itemId; }
private String quantity = "1";
public String getQuantity() { return quantity; }
public void setQuantity(String quantity) { this.quantity = quantity; }
public void reset(ActionMapping actionMapping, HttpServletRequest request) {
    // TODO: Write method body
        quantity = "1";
        itemId = "";
}
public ActionErrors validate(ActionMapping actionMapping, 
                                               HttpServletRequest request) {
    // TODO: Write method body
    throw new UnsupportedOperationException("Method not implemented");
}
}





1



