Hi,

        I found out why it did not work. However, I still do not understand why.
Anyway, following is the reason:

        The wrong version: (in ".jsp" file, I declared---)

        <html:form name="tlanForm" action="tlan"
                type="com.VillageNetworks.tlan.TlanForm"
                focus="customerName" >
--------------------------------------------------
        The right version is:

        <html:form action="tlan"
                focus="customerName" >

        Both version actually called the same "tlanForm.class", that I verified
from "servlet.log". However, the wrong one will not populate the existing
data while the right one does. Can somebody explains this?

        If this is the case, why we need to declare a form name inside the
<html:html> tag, since it will cause some problems?

Shu, Kwang-shi          | Tel 732-460-7848
Village Networks, Inc.  | Fax 732-460-9851
246 Industrial Way West |
Eatontown, NJ 078724    | email: [EMAIL PROTECTED]


-----Original Message-----
From: Kwang-Shi Shu [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 18, 2001 2:09 PM
To: [EMAIL PROTECTED]
Subject: Why ActionForm can't remember the values typed in?


Hi,

        I followed the "struts-example/logon.jsp" to create some forms.
I also creates my "tlanForm", follows the example from "logonForm". However,
when the "tlanForm" fails the validation, it returns to the original page
with
"tlanForm" being re-created and resetted (I checked it from "servlet.log").
I could not figure it out. Did somebody has similar experience? I put the
"logon.jsp" in the same directory, and it works fine.

        Here is some code snippet from "struts-config.xml"
===========================================
  <action-mappings>

    <!-- Process a tlan provisioning -->
    <action    path="/tlan"
               type="com.VillageNetworks.tlan.TlanAction"
               name="tlanForm"
              scope="request"
              input="/common/TLAN/provisioning.jsp" >
    </action>

    <!-- Process a user logon -->
    <action    path="/logon"
               type="org.apache.struts.example.LogonAction"
               name="logonForm"
              scope="request"
              input="/common/TLAN/logon.jsp">
    </action>
===========================================

        My "tlanForm" looks like this:
========================================
package com.VillageNetworks.tlan;


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;


/**
 * Form bean for the tlan provisioning page.  This form has the following
fields,
 * with default values in square brackets:
 * <ul>
 * <li><b>customerName</b> - Entered customer Name value
 * <li><b>manTagUsed</b> - whether the Man Tag is used
 * <li><b>mtuSize</b> - Entered Ether MTU Size value
 * <li><b>etherType</b> - Entered Ether Type value
 * </ul>
 *
 * @author Kwang-Shi Shu
 * @version 1.0
 * @Date: 2001/6/14
 */

public final class TlanForm extends ActionForm {


    // --------------------------------------------------- Instance
Variables


    /**
     * The Customer Name.
     */
    private String customerName = null;


    /**
     * Whether the Extreme MAN tag is used.
     */
    private boolean manTagUsed = false;


    /**
     * The Ether MTU Size.
     */
    private String mtuSize = null;

    /**
     * The Ether Type -- in Hexadecimal format, prefixed with 0x.
     */
    private String etherType = null;

    // -----------------------------------------------------------
Properties


    /**
     * Return the Customer Name.
     */
    public String getCustomerName() {

//      servlet.log("Enter TlanForm::getCustomerName");
        return (this.customerName);

    }


    /**
     * Set the customer name.
     *
     * @param customer name The new customer name
     */
    public void setCustomerName(String customerName) {

//      servlet.log("Enter TlanForm::setCustomerName");
        this.customerName = customerName;

    }


    /**
     * Return the manTagUsed.
     */
    public boolean getManTagUsed() {

//      servlet.log("Enter TlanForm::getManTagUsed");
        return (this.manTagUsed);

    }


    /**
     * Set the manTagUsed.
     *
     * @param manTagUsed The new manTagUsed
     */
    public void setManTagUsed(boolean manTagUsed) {

//      servlet.log("Enter TlanForm::setManTagUsed");
        this.manTagUsed = manTagUsed;

    }


    /**
     * Return the mtuSize.
     */
    public String getMtuSize() {

//      servlet.log("Enter TlanForm::getMtuSize");
        return (this.mtuSize);

    }


    /**
     * Set the mtuSize.
     *
     * @param mtuSize The new Ether MTU Size
     */
    public void setMtuSize(String mtuSize) {

//      servlet.log("Enter TlanForm::setMtuSize");
        this.mtuSize = mtuSize;

    }

    /**
     * Return the Ether Type.
     */
    public String getEtherType() {

//      servlet.log("Enter TlanForm::getEtherType");
        return (this.etherType);

    }


    /**
     * Set the etherType.
     *
     * @param etherType The new Ether Type
     */
    public void setEtherType(String etherType) {

        // The ether Type has to be in hexdecial format.
        // If it is not, we prepend it with "0x"

//      servlet.log("Enter TlanForm::setEtherType");

        if ( !etherType.startsWith("0x") )
                this.etherType = "0x" + etherType;
        else
                this.etherType = etherType;

    }
    // --------------------------------------------------------- Public
Methods


    /**
     * Reset all properties to their default values.
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     */
     public void reset(ActionMapping mapping, HttpServletRequest request) {

        servlet.log("Enter TlanForm::reset");

/**********
        this.customerName = null;
        this.manTagUsed = false;
        this.mtuSize = null;
        this.etherType = null;
************/

        servlet.log("Leave TlanForm::reset");

    }

    /**
     * Validate the properties that have been set from this HTTP request,
     * and return an <code>ActionErrors</code> object that encapsulates any
     * validation errors that have been found.  If no errors are found,
return
     * <code>null</code> or an <code>ActionErrors</code> object with no
     * recorded error messages.
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     */
    public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();

        servlet.log("Enter TlanForm::validate");
        servlet.log("customer Name is: " + customerName);
        servlet.log("Man Tag used is: " + manTagUsed);
        servlet.log("ether Type is: " + etherType);
        servlet.log("ether MTU Size is: " + mtuSize);

        if ((customerName == null) || (customerName.length() < 1)) {
//            errors.add("customerName", new
ActionError("error.customerName.required"));
            errors.add(ActionErrors.GLOBAL_ERROR, new
ActionError("error.customer.required"));
            servlet.log("Add errors for customerName");
        }

        // If MAN Tag is not used, the Ether Type has to be "0x8100"
        // If the MAN tag is used, we have to make sure the ether type does
not conflict
        // with existing public assignments, that are published in
        // http://standards.ieee.org/regauth/ethertype/type-pub.html
        // http://www.netwho.com/frame/ethertype.htm


        if (!manTagUsed) {
                if ( !etherType.equals("0x8100") ) {
 //                 errors.add("etherType", new
ActionError("error.etherType.standard"));
                    errors.add(ActionErrors.GLOBAL_ERROR, new
ActionError("error.etherType.standard"));
                    servlet.log("Add errors for etherType");
                }
        }
        else {
                // check the ether type against the whole set of public assignments
        }

        servlet.log("Leave TlanForm::validate");

        return errors;

    }


}
===================================================================

Shu, Kwang-shi          | Tel 732-460-7848
Village Networks, Inc.  | Fax 732-460-9851
246 Industrial Way West |
Eatontown, NJ 078724    | email: [EMAIL PROTECTED]


>

Reply via email to