commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Graham <grahamdavid1...@yahoo.com>
Subject Re: [Validator] How to create messages with more than one placeholder
Date Sun, 28 Mar 2004 21:49:50 GMT
> --- Eric.Lewis@swissinfo.ch wrote:
> > Hi
> > 
> > I just added the maxLength validator (from Struts) into my validators
> > and am
> > now trying to have a second placeholder value in my error message.
> > 
> > My form looks like this:
> >       <form name="DummyVo">
> >          <field property="name" depends="required,name,maxlength">
> >          	   <arg0 key="label.name.title"/>
> >          	   <arg1 name="maxlength" key="${var:maxlength}"
> > resource="false"/>
> >          	   <var>
> >          	   		<var-name>maxlength</var-name>
> >          	   		<var-value>5</var-value>
> >          	   </var>
> >          </field>    
> >       </form>
> > 
> > which should at least work in Struts (I'm trying to stay compatible).
> > 
> > The message would be (copied from Struts):
> > messages.validator.maxlength = The {0} can not be greater than {1}
> > characters.
> > 
> > 
> > When the check fails, I show all arguments and get this result:
> > Argument 0
> > Arg: name=null  key=label.name.title  resource=true
> > 
> > Argument 1
> > null
> > 
> > Does anyone have a clue why this doesn't work?

How are you getting the Arg objects?  My guess is you're doing something
like:
Field.getArg(0)
Field.getArg(1)

The first call returns the correct Arg object because you didn't specify a
name attribute in the xml.  The second call returns null because the xml
is <arg1 name="maxlength"...  To properly retrieve the second Arg you need
to call Field.getArg("maxlength", 1).

Note that if you don't specify a name attribute, calling
Field.getArg("maxlength", 1) will still work because it looks for the
default arg when it can't find one with the name "maxlength".

Look at Struts' Resources.getArgs() method for examples.

David


> > 
> > Also, what is the difference between having several arguments with
> > <arg0...>, <arg1...> and having them with <arg...>, <arg...>?
> > 
> > Thanks for any help!
> > Eric
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > 
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Finance Tax Center - File online. File on time.
> http://taxes.yahoo.com/filing.html
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html

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


Mime
View raw message