struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oren Livne <oli...@aoce.utah.edu>
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"
            indexedListProperty="childrenForms">
                <msg name="required" key="error.catalog.collection.null"/>
                <msg name="minlength" 
key="error.catalog.collection.minlength"/>
                <msg name="maxlength" 
key="error.catalog.collection.maxlength"/>

                <arg position="0" name="required" 
key="catalog.editItemForm.itemForm.name.label"/>
                <arg position="1" name="required" 
key="catalog.editItemForm.childrenForms.label"/>
               
                <arg position="0" name="minlength" 
key="catalog.editItemForm.itemForm.name.label"/>
                <arg position="1" name="minlength" 
key="catalog.editItemForm.childrenForms.label"/>
                <arg position="2" name="minlength" 
key="${var:minlength}" resource="false"/>
               
                <arg position="0" name="maxlength" 
key="catalog.editItemForm.itemForm.name.label"/>
                <arg position="1" name="maxlength" 
key="catalog.editItemForm.childrenForms.label"/>
                <arg position="2" name="maxlength" 
key="${var:maxlength}" resource="false"/>

                <var>
                   <var-name>minlength</var-name>
                   <var-value>3</var-value>
                </var>
                <var>
                   <var-name>maxlength</var-name>
                   <var-value>20</var-value>
                </var>
             </field>

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

-- 
======================================================================
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: olivne@aoce.utah.edu              Web:  http://ruready.net/oren
======================================================================


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message