The Struts and Tags : Struts « J2EE « Java






The Struts and Tags

The Struts and Tags
/*
Title:       Struts : Essential Skills (Essential Skills)
Authors:     Steven Holzner
Publisher:   McGraw-Hill Osborne Media
ISBN:       0072256591
*/

//ch09_01.jsp
<%@ 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>
    <head>
    <title>Using the Struts Validator</title>
    <html:base/>
</head>

<body>
    <h1>Using the Struts Validator</h1>

    <logic:messagesPresent>
        <bean:message key="errors.header"/>
        <ul>
            <html:messages id="error" property="byte">
                <li><bean:write name="error"/></li>
            </html:messages>
            <html:messages id="error" property="short">
                <li><bean:write name="error"/></li>
            </html:messages>
            <html:messages id="error" property="integer">
                <li><bean:write name="error"/></li>
            </html:messages>
            <html:messages id="error" property="long">
                <li><bean:write name="error"/></li>
            </html:messages>
            <html:messages id="error" property="float">
                <li><bean:write name="error"/></li>
            </html:messages>
            <html:messages id="error" property="floatRange">
                <li><bean:write name="error"/></li>
            </html:messages>
            <html:messages id="error" property="double">
                <li><bean:write name="error"/></li>
            </html:messages>
            <html:messages id="error" property="date">
                <li><bean:write name="error"/></li>
            </html:messages>
            <html:messages id="error" property="creditCard">
                <li><bean:write name="error"/></li>
            </html:messages>
            <html:messages id="error" property="city">
                <li><bean:write name="error"/></li>
            </html:messages>
            <html:messages id="error" property="zip">
                <li><bean:write name="error"/></li>
            </html:messages>
        </ul>
        <hr>
    </logic:messagesPresent>

    <html:form action="ch09_02">

      <bean:message key="ch09_03.byte.text"/>
      &nbsp;
      &nbsp;
      &nbsp;
      <html:text property="byte" size="15" maxlength="15"/>
      <br>
      <br>

      <bean:message key="ch09_03.short.text"/>
      &nbsp;
      &nbsp;
      &nbsp;
      <html:text property="short" size="15" maxlength="15"/>
      <br>
      <br>

      <bean:message key="ch09_03.integer.text"/>
      &nbsp;
      &nbsp;
      &nbsp;
      <html:text property="integer" size="15" maxlength="15"/>
      <br>
      <br>

      <bean:message key="ch09_03.long.text"/>
      &nbsp;
      &nbsp;
      &nbsp;
      <html:text property="long" size="15" maxlength="15"/>
      <br>
      <br>

      <bean:message key="ch09_03.float.text"/>
      &nbsp;
      &nbsp;
      &nbsp;
      <html:text property="float" size="15" maxlength="15"/>
      <br>
      <br>

      <bean:message key="ch09_03.floatRange.text"/>
      &nbsp;
      &nbsp;
      &nbsp;
      <html:text property="floatRange" size="15" maxlength="15"/>
      <br>
      <br>

      <bean:message key="ch09_03.double.text"/>
      &nbsp;
      &nbsp;
      &nbsp;
      <html:text property="double" size="15" maxlength="15"/>
      <br>
      <br>

      <bean:message key="ch09_03.date.text"/>
      &nbsp;
      &nbsp;
      &nbsp;
      <html:text property="date" size="15" maxlength="15"/>
      <br>
      <br>

      <bean:message key="ch09_03.creditCard.text"/>
      &nbsp;
      &nbsp;
      &nbsp;
      <html:text property="creditCard" size="16" maxlength="16"/>
      <br>
      <br>

      <bean:message key="ch09_03.city.text"/>
      &nbsp;
      &nbsp;
      &nbsp;
      <html:text property="city" size="16" maxlength="16"/>
      <br>
      <br>

      <bean:message key="ch09_03.zip.text"/>
      &nbsp;
      &nbsp;
      &nbsp;
      <html:text property="zip" size="5" maxlength="5"/>
      <br>
      <br>

      <html:submit property="submit">
         Submit
      </html:submit>
      &nbsp;
      <html:reset>
         Reset
      </html:reset>

</html:form>

</body>
</html:html>

//ch09_04.jsp
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<HTML>
    <HEAD>
        <TITLE>Here's Your Data...</TITLE>
    </HEAD>
    
    <BODY>
        <H1>Here's Your Data...</H1>

        <bean:message key="ch09_03.byte.text"/>: 
        <bean:write name="ch09_03" property="byte"/>
        <BR>
        <BR>

        <bean:message key="ch09_03.short.text"/>: 
        <bean:write name="ch09_03" property="short"/>
        <BR>
        <BR>

        <bean:message key="ch09_03.integer.text"/>: 
        <bean:write name="ch09_03" property="integer"/>
        <BR>
        <BR>

        <bean:message key="ch09_03.long.text"/>: 
        <bean:write name="ch09_03" property="long"/>
        <BR>
        <BR>

        <bean:message key="ch09_03.float.text"/>: 
        <bean:write name="ch09_03" property="float"/>
        <BR>
        <BR>

        <bean:message key="ch09_03.floatRange.text"/>: 
        <bean:write name="ch09_03" property="floatRange"/>
        <BR>
        <BR>

        <bean:message key="ch09_03.double.text"/>: 
        <bean:write name="ch09_03" property="double"/>
        <BR>
        <BR>

        <bean:message key="ch09_03.date.text"/>: 
        <bean:write name="ch09_03" property="date"/>
        <BR>
        <BR>

        <bean:message key="ch09_03.creditCard.text"/>: 
        <bean:write name="ch09_03" property="creditCard"/>
        <BR>
        <BR>

        <bean:message key="ch09_03.city.text"/>: 
        <bean:write name="ch09_03" property="city"/>
        <BR>
        <BR>

        <bean:message key="ch09_03.zip.text"/>: 
        <bean:write name="ch09_03" property="zip"/>
        <BR>

    </BODY>
</HTML>

package ch09;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;

public final class ch09_02 extends Action {

    public ActionForward execute(ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response)
        throws Exception 
    {

        return mapping.findForward("success");

    }

}
package ch09;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.ValidatorForm;


public final class ch09_03 extends ValidatorForm { 

    private String byteData = null;
    private String shortData = null;
    private String integerData = null;
    private String longData = null;
    private String floatData = null;
    private String floatDataRange = null;
    private String doubleData = null;
    private String dateData = null;
    private String creditData = null;
    private String cityData = null;
    private String zipData = null;

    public String getByte() 
    {
       return byteData;
    }

    public void setByte(String byteData) 
    {
         this.byteData = byteData;
    }

    public String getShort() 
    {
       return shortData;
    }

    public void setShort(String shortData) 
    {
         this.shortData = shortData;
    }

    public String getInteger() 
    {
       return integerData;
    }

    public void setInteger(String integerData) 
    {
         this.integerData = integerData;
    }

    public String getLong() 
    {
       return longData;
    }

    public void setLong(String longData) 
    {
         this.longData = longData;
    }

    public String getFloat() 
    {
       return floatData;
    }

    public void setFloat(String floatData) 
    {
         this.floatData = floatData;
    }

    public String getFloatRange() 
    {
       return floatDataRange;
    }

    public void setFloatRange(String floatDataRange) 
    {
          this.floatDataRange = floatDataRange;
    }

    public String getDouble() 
    {
       return doubleData;
    }

    public void setDouble(String doubleData) 
    {
         this.doubleData = doubleData;
    }

    public String getDate() 
    {
       return dateData;
    }

    public void setDate(String dateData) 
    {
         this.dateData = dateData;
    }

    public String getCreditCard() 
    {
       return creditData;
    }

    public void setCreditCard(String creditData) 
    {
         this.creditData = creditData;
    }

    public String getCity() 
    {
       return cityData;
    }

    public void setCity(String cityData) 
    {
         this.cityData = cityData;
    }

    public String getZip() 
    {
       return zipData;
    }

    public void setZip(String zipData)   
    {
         this.zipData = zipData;
    }

    public void reset(ActionMapping mapping, HttpServletRequest request) 
    {
       byteData = null;
       shortData = null;
       integerData = null;
       longData = null;
       floatData = null;
       floatDataRange = null;
       doubleData = null;
       dateData = null;
       creditData = null;
       cityData = null;
       zipData = null;
    }
}

           
       








Struts-Essential-Skills-ch09.zip( 1,439 k)

Related examples in the same category

1.Exercise 1: Building your first Struts ApplicationExercise 1: Building your first Struts Application
2.Exercise 2: Improving your first Struts Application Exercise 2: Improving your first Struts Application
3.Exercise 3: Using JSTL, Struts-EL etcExercise 3: Using JSTL, Struts-EL etc
4.Struts Recipes: Build Struts with Ant
5.Using bean:resource to expose the struts.config.xml to your view
6.Create a pluggable validator for cross-form validation 2Create a pluggable validator for cross-form validation 2
7.Struts: Generate a response with XSL
8. Hibernate and Struts  Hibernate and Struts
9. In-container testing with StrutsTestCase and Cactus
10.Exercise 4: Applying Gof and J2EE Patterns:Deploy to WebLogic and Test
11.Exercise 5: Search, List, Action Chaining, Editable List Form
12.Exercise 6: Paging
13.Exercise 7: Better Form and Action Handling
14.Exercise 8: Creating Struts Modules
15.Exercise 9: Using Commons Validator with Struts
16.Exercise 10: Using Struts and Tiles
17.Essential Struts ActionEssential Struts Action
18.A Full Struts ApplicationA Full Struts Application
19.Struts Creating the ViewStruts Creating the View
20.Struts: Creating the ModelStruts: Creating the Model
21.Struts: Creating the ControllerStruts: Creating the Controller
22.Creating Custom TagsCreating Custom Tags
23.The Struts TagsThe Struts Tags
24.Web Services and the Validator and Tile PackagesWeb Services and the Validator and Tile Packages
25.Struts Framework: A Sample Struts ApplicationStruts Framework: A Sample Struts Application
26.Struts Framework Validator
27.Struts Framework: TilesStruts Framework: Tiles
28.Struts Framework: Declarative Exception Handling
29.Struts: Internationalizing Struts Applications
30.Securing Struts Applications
31.Testing Struts Applications
32.Struts exampleStruts example
33.Blank Struts templateBlank Struts template
34.Struts Framework
35.Struts: bank application
36.Struts applicationStruts application
37.Struts application 2Struts application 2