You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by CM...@harland.net on 2003/07/21 23:35:31 UTC

Create a new Valiation Rule

Hi,

I'm trying to create a new Validation Rule, but couldn't figure out how to
get the field value back as an Object instead of a String.

I created the validation method as:

public static boolean validateImageInfo(
     Object bean,
     ValidatorAction va,
     Field field,
     ActionErrors errors,
     HttpServletRequest request,
     ServletContext application) {

     String value = ValidatorUtils.getValueAsString(bean, field.getProperty
());

     ....

 }

but what I really what is getting an Object back (FormFile), instead of
String. I went through the org.apache.commons.validator.*, but couldn't
find any method that accomplishes this. Anyone has any idea? Is this even
possible?

Thanks,

Changyi


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


RE: Create a new Valiation Rule

Posted by Yansheng Lin <ya...@isogis.com>.
So casting didn't work for you?

Maybe you are trying to do too much in the validateImageInfo() method.   I view
it as a yes or no validation.  For more complex businese-rule validation, I
would override the validate() method in the Form class instead.  That way, you
can access the bean object.

Hope this helps.

-----Original Message-----
From: CMao@harland.net [mailto:CMao@harland.net] 
Sent: July 21, 2003 3:36 PM
To: struts-user@jakarta.apache.org
Subject: Create a new Valiation Rule


Hi,

I'm trying to create a new Validation Rule, but couldn't figure out how to
get the field value back as an Object instead of a String.

I created the validation method as:

public static boolean validateImageInfo(
     Object bean,
     ValidatorAction va,
     Field field,
     ActionErrors errors,
     HttpServletRequest request,
     ServletContext application) {

     String value = ValidatorUtils.getValueAsString(bean, field.getProperty
());

     ....

 }

but what I really what is getting an Object back (FormFile), instead of
String. I went through the org.apache.commons.validator.*, but couldn't
find any method that accomplishes this. Anyone has any idea? Is this even
possible?

Thanks,

Changyi


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


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