Re: I can't put 'maxlength' validator values in my .properties file?

2006-08-16 Thread Niall Pemberton

On 8/16/06, Scott Van Wart <[EMAIL PROTECTED]> wrote:

I tried the following:

  


  

Now I figured that this would cause the maxlength validator to get the
value for maxlength from message resources, rather than hardcoding it
with var, var-name and var-value tags.  But it doesn't!  It only uses
this to pass to the {0} in the error message (in
org.apache.struts.validator.FieldChecks.validateMaxLength, version 1.1.4):

  // No reference to resources at this point, only in the exception handler
  int max = Integer.parseInt(field.getVarValue("maxlength"));

Am I missing something?


Yes - two things:

1) The maxlength validator never gets the "variable" values used to
validate from  elements - they are only ever used for "error
message arguments". So you need to specify a  element to specify
the maxlength value.

2) Support for "variables" being specified in "resources" was added to
Struts 1.3.x (and not the 1.2.x branch) - so even if you upgraded to
Validator 1.2.0 or Validator 1.3.0 its not going to work with Strutsb
1.2.x - try Struts 1.3.5

http://wiki.apache.org/jakarta-commons/ValidatorVersion120

Niall



- Scott


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



Re: I can't put 'maxlength' validator values in my .properties file?

2006-08-16 Thread Scott Van Wart

David Friedman wrote:

Right, but the invoked Resources.getActionMessage() has calls inside it for
the bundle in the current trunk:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apa
che/struts/validator/Resources.java?view=markup

It looks like it hasn't changed from the 1.2.X branch and it is definitely
different compared to the 1.1.X branch.  If you correct the problem to the
Resources class you might want to submit it to JIRA.
  

http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/validator/FieldChecks.java?revision=289694&view=markup

This is the first revision with the resource support (2005 Sep 17).  
Struts 1.2.9 was released 2006 Mar 22, but doesn't include this!


- Scott

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



Re: I can't put 'maxlength' validator values in my .properties file?

2006-08-16 Thread Scott Van Wart

David Friedman wrote:

Right, but the invoked Resources.getActionMessage() has calls inside it for
the bundle in the current trunk:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apa
che/struts/validator/Resources.java?view=markup

It looks like it hasn't changed from the 1.2.X branch and it is definitely
different compared to the 1.1.X branch.  If you correct the problem to the
Resources class you might want to submit it to JIRA.
  
Geesh that's weird... I'm glad you sent the link to the trunk.  
FieldChecks specifically is what is causing me problems.  getVarValue is 
called indistriminately in my copy of struts (1.2.9 to the very, very 
best of my knowledge), but according to 
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/validator/FieldChecks.java?view=markup, 
the trunk's validateMaxLength is completely different... sigh... time to 
check some more JARs.  Actually, I'm going to check the 1.2.x branch 
first to see whether or not I'm completely off my rocker.  In between 
your posts I wrote my own validateMaxLength that does the same thing 
(only not as generically(sp) as the trunk's version).  You should really 
type your posts faster (kidding! :)


Thanks again!

- Scott

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



RE: I can't put 'maxlength' validator values in my .properties file?

2006-08-16 Thread David Friedman
Right, but the invoked Resources.getActionMessage() has calls inside it for
the bundle in the current trunk:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apa
che/struts/validator/Resources.java?view=markup

It looks like it hasn't changed from the 1.2.X branch and it is definitely
different compared to the 1.1.X branch.  If you correct the problem to the
Resources class you might want to submit it to JIRA.

Regards,
David

-Original Message-
From: Scott Van Wart [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 16, 2006 1:30 PM
To: Struts Users Mailing List
Subject: Re: I can't put 'maxlength' validator values in my .properties
file?


David Friedman wrote:
> I think you need to have at least Struts v1.2.8 unless you manually
upgraded
> the Commons Validator jar up to version 1.2.0.  If I understand correctly,
> validator versions before 1.2.0 (Struts < 1.2.8) don't actually make use
of
> the "bundle" attribute in your validator xml files.
>
> So, what version of Struts are you using (1.1.4?) and/or what version of
the
> Commons Validator are you using?  Have you tried replacing the commons
> validator jar?  I think I read that some people have tried that for older
> versions but I'm not positive.
>
Another issue is that the FieldChecks class is a part of Struts (1.2.9)
and not the commons validator.  The line where I would assume it should
grab it from the resources bundle doesn't contain any resource references:

/**
 *  Checks if the field's length is less than or equal to the
maximum value.
 *  A Null will be considered an error.
 *
 * @param  bean The bean validation is being performed on.
 * @param  va   The ValidatorAction that is
currently being performed.
 * @param  fieldThe Field object associated with
the current
 *  field being validated.
 * @param  errors   The ActionMessages object to add
errors to if any
 *  validation errors occur.
 * @param validator The Validator instance, used to access
 *  other field values.
 * @param  request  Current request object.
 * @return True if stated conditions met.
 */
public static boolean validateMaxLength(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {

String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean,
field.getProperty());
}

if (value != null) {
try {
int max =
Integer.parseInt(field.getVarValue("maxlength")); // < RIGHT HERE

if (!GenericValidator.maxLength(value, max)) {
errors.add(field.getKey(),
Resources.getActionMessage(validator, request, va, field));

return false;
}
} catch (Exception e) {
errors.add(field.getKey(),
Resources.getActionMessage(validator, request, va, field));
return false;
}
}

return true;
}


So it's looking like I'm going to need to write my own validator.  OH
well

- Scott


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



Re: I can't put 'maxlength' validator values in my .properties file?

2006-08-16 Thread Scott Van Wart

David Friedman wrote:

I think you need to have at least Struts v1.2.8 unless you manually upgraded
the Commons Validator jar up to version 1.2.0.  If I understand correctly,
validator versions before 1.2.0 (Struts < 1.2.8) don't actually make use of
the "bundle" attribute in your validator xml files.

So, what version of Struts are you using (1.1.4?) and/or what version of the
Commons Validator are you using?  Have you tried replacing the commons
validator jar?  I think I read that some people have tried that for older
versions but I'm not positive.
  
Another issue is that the FieldChecks class is a part of Struts (1.2.9) 
and not the commons validator.  The line where I would assume it should 
grab it from the resources bundle doesn't contain any resource references:


   /**
*  Checks if the field's length is less than or equal to the 
maximum value.

*  A Null will be considered an error.
*
* @param  bean The bean validation is being performed on.
* @param  va   The ValidatorAction that is 
currently being performed.
* @param  fieldThe Field object associated with 
the current

*  field being validated.
* @param  errors   The ActionMessages object to add 
errors to if any

*  validation errors occur.
* @param validator The Validator instance, used to access
*  other field values.
* @param  request  Current request object.
* @return True if stated conditions met.
*/
   public static boolean validateMaxLength(Object bean,
   ValidatorAction va, Field field,
   ActionMessages errors,
   Validator validator,
   HttpServletRequest request) {

   String value = null;
   if (isString(bean)) {
   value = (String) bean;
   } else {
   value = ValidatorUtils.getValueAsString(bean, 
field.getProperty());

   }

   if (value != null) {
   try {
   int max = 
Integer.parseInt(field.getVarValue("maxlength")); // < RIGHT HERE


   if (!GenericValidator.maxLength(value, max)) {
   errors.add(field.getKey(), 
Resources.getActionMessage(validator, request, va, field));


   return false;
   }
   } catch (Exception e) {
   errors.add(field.getKey(), 
Resources.getActionMessage(validator, request, va, field));

   return false;
   }
   }

   return true;
   }


So it's looking like I'm going to need to write my own validator.  OH 
well


- Scott

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



Re: I can't put 'maxlength' validator values in my .properties file?

2006-08-16 Thread Scott Van Wart

David Friedman wrote:

I think you need to have at least Struts v1.2.8 unless you manually upgraded
the Commons Validator jar up to version 1.2.0.  If I understand correctly,
validator versions before 1.2.0 (Struts < 1.2.8) don't actually make use of
the "bundle" attribute in your validator xml files.

So, what version of Struts are you using (1.1.4?) and/or what version of the
Commons Validator are you using?  Have you tried replacing the commons
validator jar?  I think I read that some people have tried that for older
versions but I'm not positive.
  
Validator 1.1.4 (according to the manifest, and Eclipse seems to think 
the source syncs up properly so I'm convinced), the one that came with 
Struts 1.2.9 (which I'm using too).


I'll try updating the validator, thanks!

- Scott

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



RE: I can't put 'maxlength' validator values in my .properties file?

2006-08-16 Thread David Friedman
I think you need to have at least Struts v1.2.8 unless you manually upgraded
the Commons Validator jar up to version 1.2.0.  If I understand correctly,
validator versions before 1.2.0 (Struts < 1.2.8) don't actually make use of
the "bundle" attribute in your validator xml files.

So, what version of Struts are you using (1.1.4?) and/or what version of the
Commons Validator are you using?  Have you tried replacing the commons
validator jar?  I think I read that some people have tried that for older
versions but I'm not positive.

Regards,
David

-Original Message-
From: Scott Van Wart [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 16, 2006 1:04 PM
To: user@struts.apache.org
Subject: I can't put 'maxlength' validator values in
my .properties file?

I tried the following:

  


  

Now I figured that this would cause the maxlength validator to get the
value for maxlength from message resources, rather than hardcoding it
with var, var-name and var-value tags.  But it doesn't!  It only uses
this to pass to the {0} in the error message (in
org.apache.struts.validator.FieldChecks.validateMaxLength, version 1.1.4):

  // No reference to resources at this point, only in the exception handler
  int max = Integer.parseInt(field.getVarValue("maxlength"));

Am I missing something?

- Scott


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