The <arg> element relates solely to the validation message and is a
"replacement parameter" in that message - with the position indicating
which parameter to replace. So if you have a validation message in you
resource bundles that looks like this:
minimum.error={0} must be greater than {1}
<arg position="0"...> will replace {0}
<arg position="1"...> will replace {1}
The <var> elements are a completely separate thing - each validator
has specific requirements to be configured with certain variables - so
for example the "mask" validator needs a "mask" var, the "intRange"
validator needs "min" and "max" <var> elements and so on.
Sometimes people want to display the configured variables in their
error messages - in that case theres a special notation for doing so
${var:....} in the <arg> element. So in the case of the "intRange"
validation you may want to show the minimum and maximum values in the
error message. So you would do something like:
<arg position="1" key="${var:min}" resource="false"/>
<arg position="2" key="${var:max}" resource="false"/>
<var><var-name>min</var-name>
<var-value>10</var-value>
</var>
<var><var-name>max</var-name>
<var-value>99</var-value>
</var>
The struts-examples webapp has some "validator" examples in it which
probably would help you to understand how it all hangs together.
Niall
On 7/13/06, Adam Gordon <[EMAIL PROTECTED]> wrote:
I'm reading the validator 1.1.3 DTD file and I'm trying to understand the
purpose of the "position" attribute in the <arg> element and the <arg>
element itself. According to the DTD: 'The "arg" element defines a
replacement value to use with the message template for this validator or
this field.'
Can someone please dumb this down for me?
So, if I have:
<field property="meetingDate"
depends="required, date, maxlength, mask">
<arg position="0" key="prompt.date"/>
<arg position="1"
name="maxlength"
key="${var:maxlength}"
resource="false"/>
<var>
<var-name>datePattern</var-name>
<var-value>MM/dd/yyyy</var-value>
</var>
<var>
<var-name>maxlength</var-name>
<!-- the value here MUST match the maxlength attribute in the JSP
for the text field with this property name -->
<var-value>12</var-value>
</var>
<var>
<var-name>mask</var-name>
<var-value>^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(2
9|30)|(0?[13578]|1[02])/31)/(20)((0[6-9])|(10))|0?2/29/((20)(0[48])))$</var-
value>
</var>
</field>
Does the position attribute refer to the "index" of the <var> element? So
that it knows which "rule" to match?
Thanks,
-Adam
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]