Brandon--
Thanks for confirming that the approach can actually work. Turns out
the root of my problem was in fact the line that declares the Map in the
form bean, which needs to be something like
private Map map = new HashMap();
rather than
private Map map = null;
The "other" problem was a typo in my validation.xml file :-(
Your sample snippets were helpful in making this all clear to me.
Thanks again,
--Ken
From: Brandon Goodin <[EMAIL PROTECTED]>
Subject: Using Map in ActionForm (ValidatorForm)
Date: Sat, 22 Feb 2003 18:10:51 -0700
Content-Type: text/plain;
charset="us-ascii"
This is what my action form looks like. You can ignore the LinkedHashMap
and
use a regular HashMap. The only difference really is that I use the
'this.'
notation to access the local Map.
Basically, I have a single Map that has accessor methods to get/set
individual properties and I have accessor methods to get/set the whole
Map.
ValidatorActionForm
...
protected LinkedHashMap fields = new LinkedHashMap();
...
/**
* Returns the field.
* @return Object
*/
public Object getField(String key) {
return fields.get(key);
}
/**
* Method setField.
* @param key
* @param value
*/
public void setField(String key, Object value) {
this.fields.put(key,value);
}
/**
* Method getFields.
* @return Map
*/
public LinkedHashMap getFields() {
return fields;
}
/**
* Sets the fields.
* @param fields The fields to set
*/
public void setFields(LinkedHashMap fields) {
this.fields = fields;
}
...
My jsp tag property looks like the following:
<html:text property="fields(phoneAreaCode)" size="24"/>
My validation.xml looks like the following:
<form-validation>
<formset>
<form name="/contact/send">
...
<field property="fields(phoneAreaCode)"
depends="integer,minlength">
<arg0 key="${var:field}"
resource="false"/>
<arg1 name="minlength"
key="${var:minlength}"
resource="false"/>
<var>
<var-name>field</var-name>
<var-value>Area Code</var-value>
</var>
<var>
<var-name>minlength</var-name>
<var-value>3</var-value>
</var>
</field>
...
</form>
</formset>
</form-validation>
It works like a champ.
Brandon Goodin
Phase Web and Multimedia
PO Box 85
Whitefish MT 59937
P (406) 862-2245
F (406) 862-0354
[EMAIL PROTECTED]
http://www.phase.ws
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]