Re: [VALIDATOR] Validating Date with DynaValidator

2002-09-04 Thread Marco Maier

Axel Stahlhut wrote:
 Sorry for posting this one again, but its a bit urgent and maybe i have a chance 
marking it as a post concerning [Validator].
 
 Validating a Date with the Struts-Validator Framework works fine, but if the field i 
want to validate is not a required field and may be empty, the validator always 
reports an error, even if if i remove the depends=required in the 
validation-rules.xml. 
 Do i have to implement the Validator-class in a way that it doesnt validate empty 
dates or is there any declarative way to solve this?
 Thanks for any help.
 
 Axel
 
 This is my validation-rules.xml:
 
   validator name=date
 classname=org.apache.struts.util.StrutsValidator
method=validateDate
  methodParams=java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest
msg=errors.date
jsFunctionName=DateValidations
 
 and the validation.xml:
 
 field property=beginEmployment depends=date
 arg0 key=personal.data.beginEmployment /
 var
 var-namedatePattern/var-name
 var-valuedd.MM./var-value
 /var
 /field
 
 
 

Hi Axel,

you can subclass the DynaValidatorForm to override the validator method.
There you can check if the date field is empty, something like that

public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
{
   String date = null;

   if (((date = (String) this.get(yourDateField)) == null)
|| (date.length == 0))
   {
 // do no validation
 return null;
   }
   return super.validate(mapping, request);
}

Hope this helps.

Marco


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




[VALIDATOR] Validating Date with DynaValidator

2002-09-03 Thread Axel Stahlhut

Sorry for posting this one again, but its a bit urgent and maybe i have a chance 
marking it as a post concerning [Validator].

Validating a Date with the Struts-Validator Framework works fine, but if the field i 
want to validate is not a required field and may be empty, the validator always 
reports an error, even if if i remove the depends=required in the 
validation-rules.xml. 
Do i have to implement the Validator-class in a way that it doesnt validate empty 
dates or is there any declarative way to solve this?
Thanks for any help.

Axel

This is my validation-rules.xml:

  validator name=date
classname=org.apache.struts.util.StrutsValidator
   method=validateDate
 methodParams=java.lang.Object,
   org.apache.commons.validator.ValidatorAction,
   org.apache.commons.validator.Field,
   org.apache.struts.action.ActionErrors,
   javax.servlet.http.HttpServletRequest
   msg=errors.date
   jsFunctionName=DateValidations

and the validation.xml:

field property=beginEmployment depends=date
arg0 key=personal.data.beginEmployment /
var
var-namedatePattern/var-name
var-valuedd.MM./var-value
/var
/field





Re: [VALIDATOR] Validating Date with DynaValidator

2002-09-03 Thread Rick Reumann

On Tuesday, September 3, 2002, 5:45:57 PM, Axel Stahlhut wrote:


AS This is my validation-rules.xml:

AS   validator name=date
AS classname=org.apache.struts.util.StrutsValidator
ASmethod=validateDate
AS  methodParams=java.lang.Object,
ASorg.apache.commons.validator.ValidatorAction,
ASorg.apache.commons.validator.Field,
ASorg.apache.struts.action.ActionErrors,
ASjavax.servlet.http.HttpServletRequest
ASmsg=errors.date
ASjsFunctionName=DateValidations

AS and the validation.xml:

AS field property=beginEmployment depends=date
AS arg0 key=personal.data.beginEmployment /
AS var
AS var-namedatePattern/var-name
AS var-valuedd.MM./var-value
AS /var
AS /field

I think you need the depends=required in the validation-rules
for date. You don't want it in the validation.xml but in the rule
I think you might need it to get it to work correctly. I have the
depends=required in the validation-rules.xml for date and my
dates are getting validated if I leave the field blank, so give it
a try. Not positive that's the problem though.

--

Rick

mailto:[EMAIL PROTECTED]


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]