struts, the validator, & map-backed action forms

D

Dave Kawczynski

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>
 
D

Dave Kawczynski

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:)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top