Thanks Niall for your prompt reply. I appreciate it. Siva
-----Original Message----- From: Niall Pemberton [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 16, 2005 6:06 PM To: Jakarta Commons Developers List Subject: Re: [Validator] how to give user input in Arg It would be pretty straight forward to do. You need to define some convention to identify that you want a property value in your args, then when you generate the message, replace any such values. For example.... <field property="dateOfBirth" depends="required, date"> <arg0 key="x.dateOfBirth"/> <arg1 key="${dateOfBirth}" resource="false"/> <var> <var-name>datePatternStrict</var-name> <var-value>dd/mm/yyyy</var-value> </var> </field> Then in your validators (e.g. date validator), when you get the message if the validation fails - then you need to replace any arg values. Something like..... public String getMessage(Object bean, Field field, ValidatorAction va, MessageResources resources) { String validationName = va.getName(); // Get the message Msg msg = field.getMessage(validationName); if (msg == null) { msg = va.getMsg(); } // Process args String[] args = field.getArgs(validationName); for (int i = 0; i < args.length; i++ ) { if (args[i] == null) { continue; if (args[i].isResource()) { args[i] = resources.getMessage(args[i], null); } else if (args[i].startsWith("${")) { String property = args[i].substring(2, args[i].length -2); args[i] = ValidatorUtils.getValueAsString(bean, property); } } // retrieve message from resources return resources.getMessage(msg.getKey(), args); } hth Niall ----- Original Message ----- From: "Daggumalli, Sivaji" <[EMAIL PROTECTED]> Sent: Wednesday, November 16, 2005 11:25 PM Sorry to confuse you Niall. Actually we are using Commons Validator as standalone project. (Not with Struts). I was wrongly mentioned that earlier by mistake. Is it possible to extend commons Validator 1.2.0 to achieve this behavior? Regards and Thanks in advance. Siva -----Original Message----- From: Niall Pemberton [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 16, 2005 5:14 PM To: Jakarta Commons Developers List Subject: Re: [Validator] how to give user input in Arg There is no way to do this in Struts/Validator currently - unless you write your own versions of the Struts validators and implement a mechanism to do this when generating the error message. Niall ----- Original Message ----- From: "Daggumalli, Sivaji" <[EMAIL PROTECTED]> Sent: Wednesday, November 16, 2005 10:04 PM Hi, Afternoon got a commons Validator problem... We are using the Struts Validator and in my validation.xml i have: <form name="myForm"> <field property="dateOfBirth" depends="required, date"> <arg0 key="x.dateOfBirth"/> <var> <var-name>datePatternStrict</var-name> <var-value>dd/mm/yyyy</var-value> </var> </field> </form> In Application Resources i have: errors.date={0} is not a date. x.dateOfBirth=Date Of Birth If the user entered date is in the wrong format an error message is produced: Date Of Birth is not a date. This is all good. But what I am trying to achieve is including the input value in the message. I know in the validation.xml you can specify and use vars in the error message (for example): <arg1 key="${var:minlength}" name="minlength" resource="false" /> <var> <var-name>minlength</var-name> <var-value>10</var-value> </var> What I want to do is replace the <var-value> (the literal vaue '10') with the user input. I have tried many things ${field:dateOfBirth}, ${dateOfBirth}, ${myForm.dateOfBirth} but none have worked. Regards and Thanks in advance, Siva --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
