struts, the validator, & map-backed action forms

Discussion in 'Java' started by Dave Kawczynski, Apr 16, 2004.

  1. Is the validator compatable with map-backed ActionForms?

    I am having problems implementing the validator when the ActionForm
    involved in the form submission is backed by a HashMap. Specifically,
    the generated client-sided script does not contain any calls to
    validation functions.

    Any help would be greatly appreicated!
    -dave


    PROBLEM: for an ActionForm named testForm, the generated javascript
    begins as follows:
    function validateTestForm(form) {
    if (bCancel)
    return true;
    else
    return true;
    }

    Here are the associated components:
    validator.xml:
    <form name="mapBasedFormTest">
    <field name="property(firstName)" depends="maxlength">
    <arg0 key="errors.maxlength"/>
    <arg1 key="test.firstname.displayname"/>
    <arg2 name="maxlength" key="${var:maxlength}"
    resource="false"/>
    <var>
    <var-name>maxlength</var-name>
    <var-value>10</var-value>
    </var>
    </field>
    <field name="property(lastName)" depends="maxlength">
    <arg0 key="errors.maxlength"/>
    <arg1 key="test.lastname.displayname"/>
    <arg2 name="maxlength" key="${var:maxlength}"
    resource="false"/>
    <var>
    <var-name>maxlength</var-name>
    <var-value>50</var-value>
    </var>
    </field>
    </form>

    ActionForm:
    import org.apache.struts.action.ActionForm;
    import java.util.HashMap;
    public class FormTest extends ActionForm
    {
    protected HashMap properties = new java.util.HashMap();

    public void setProperty(String key, Object value)
    {
    this.properties.put(key, value);
    }

    public Object getProperty(String key)
    {
    return this.properties.get(key);
    }
    }

    test.jsp:
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <html>
    <body>
    <html:form action="/test">
    <bean:message key="test.firstname.displayname"/>
    <html:text property="property(firstName)"/>
    <br/>
    <bean:message key="test.lastname.displayname"/>
    <html:text property="property(lastName)"/>
    <html:submit/>
    </html:form>
    <html:javascript formName="mapBasedFormTest"/>
    </body>
    </html>
    Dave Kawczynski, Apr 16, 2004
    #1
    1. Advertising

  2. My problem was in validation.xml: using a "name" attribute to specify
    a field's name is not advised. The "property" attribute works much
    better.
    :eek:)

    > <form name="mapBasedFormTest">
    > <field name="property(firstName)" depends="maxlength">
    > <arg0 key="errors.maxlength"/>
    > <arg1 key="test.firstname.displayname"/>
    > <arg2 name="maxlength" key="${var:maxlength}"
    > resource="false"/>
    > <var>
    > <var-name>maxlength</var-name>
    > <var-value>10</var-value>
    > </var>
    > </field>
    > <field name="property(lastName)" depends="maxlength">
    > <arg0 key="errors.maxlength"/>
    > <arg1 key="test.lastname.displayname"/>
    > <arg2 name="maxlength" key="${var:maxlength}"
    > resource="false"/>
    > <var>
    > <var-name>maxlength</var-name>
    > <var-value>50</var-value>
    > </var>
    > </field>
    > </form>
    Dave Kawczynski, Apr 19, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Bloggs
    Replies:
    1
    Views:
    704
    Sudsy
    Aug 3, 2003
  2. Wendy Smoak

    cached backed or self-emptying map

    Wendy Smoak, Apr 29, 2005, in forum: Java
    Replies:
    2
    Views:
    426
    Wendy Smoak
    Apr 29, 2005
  3. Replies:
    0
    Views:
    3,365
  4. Replies:
    0
    Views:
    711
  5. Stefan Ram

    Searching a disk-backed Map

    Stefan Ram, Aug 18, 2009, in forum: Java
    Replies:
    24
    Views:
    1,283
    Arne Vajhøj
    Aug 29, 2009
Loading...

Share This Page