struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oren Livne <>
Subject Can Validator error messages use the field's properties?
Date Sat, 03 Feb 2007 02:05:50 GMT
Dear All:

I'm using Struts 1.3.5 in my content management web application. I have 
a form with a dynamic
list. To validate it, I used the following in my validator.xml to loop 
over all elements of the
list "childrenForm" of my main form:

            <field property="name" depends="required,minlength,maxlength"
                <msg name="required" key="error.catalog.collection.null"/>
                <msg name="minlength" 
                <msg name="maxlength" 

                <arg position="0" name="required" 
                <arg position="1" name="required" 
                <arg position="0" name="minlength" 
                <arg position="1" name="minlength" 
                <arg position="2" name="minlength" 
key="${var:minlength}" resource="false"/>
                <arg position="0" name="maxlength" 
                <arg position="1" name="maxlength" 
                <arg position="2" name="maxlength" 
key="${var:maxlength}" resource="false"/>


Right now, this will show the same error message for all elements, if 
their name is not in the submitted
form. Furthermore, the same message may be shown multiple times with 
<html:errors/>, if multiple names
are not filled out by the user). However, I would like to customize the 
error message per element of the list,
and say something like

Your field 'Name' for Category #2 ('Mathematics') is required. Please 
enter a Name.

Here 'Mathematics' is the actual field's name property and index is the 
index of it in the list (or
the index plus 1, say).

- Is there a way to use something like 'childrenForm[].name' as the 
value of <arg position="2">,
instead of using a key? I know it's possible to reference '[]' in the 
variable 'test', but not in any other variable.
- Is there a way to reference the index of the element in the list in an 
error message?
- Is there a way to reference an expression that depends on the index, 
like an EL expression (e.g. "${index+1}")?

Thanks so much in advance,

Oren Livne, Ph.D.
Research Assistant Professor of Mathematics
RUReady Software Architect

Academic Outreach and Continuing Education
1901 East South Campus Dr., Room 2197-D
University of Utah, Salt Lake City, UT 84112-9399
Tel  : (801) 581-6831     Cell: (801) 631-3885     Fax: (801) 585-5414
Email:              Web:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message