You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Manisha Sathe <ma...@yahoo.com> on 2005/01/20 03:40:30 UTC

Validation problem - for a form with multiple names

I have a form whose fields are from an dynamic customer array. I display Customer name and giving i/p field  for Amount to enter. 
 
The JSP might contain 2-3 text fields called amt against different customers (I am identifying it with IDs)
 
My form bean is something like this,
 
public class AddressForm extends ValidatorForm
//ActionForm
{
...
  private String[] amt;
 ...
 public String[] getAmt()
 {
  return this.amt;
 }
 public void setAmt(String[] amt)
 {
  this.amt = amt;
 }
 
...
}
 
I am using Validator, 
 
validation.xml is something like this
 
            <field property="amt"
                depends="required">
                <arg0 key="amt.displayname"/>
            </field>

--------------------------------------------------------------------------------
 
1) When validation fails and it comes back to jsp form -BUT  the bydefault values of Amount is something like : [Ljava.lang.String;@f2da21
 
I understand this is because i have declared it as an array. But how to get rid of this. 
 
2)I face a problem when i also want to validate as float. As i/p taken is amt[1], amt[2] ... it never gets validated as float where as i want to validate individual i/p text field as float.
 
How can i achieve it ?
 
Pls guide me
 
Thanks and regards
Manisha
 
 
 
 

		
---------------------------------
Do you Yahoo!?
 Yahoo! Search presents - Jib Jab's 'Second Term'

Re: Validation problem - for a form with multiple names

Posted by Matt Bathje <mp...@ntsource.com>.
Manisha Sathe wrote:
> I have a form whose fields are from an dynamic customer array. I display Customer name and giving i/p field  for Amount to enter. 
>  
> The JSP might contain 2-3 text fields called amt against different customers (I am identifying it with IDs)
>  
> My form bean is something like this,
>  
> public class AddressForm extends ValidatorForm
> //ActionForm
> {
> ...
>   private String[] amt;
>  ...
>  public String[] getAmt()
>  {
>   return this.amt;
>  }
>  public void setAmt(String[] amt)
>  {
>   this.amt = amt;
>  }
>  
> ...
> }
>  
> I am using Validator, 
>  
> validation.xml is something like this
>  
>             <field property="amt"
>                 depends="required">
>                 <arg0 key="amt.displayname"/>
>             </field>
> 
> --------------------------------------------------------------------------------
>  
> 1) When validation fails and it comes back to jsp form -BUT  the bydefault values of Amount is something like : [Ljava.lang.String;@f2da21
>  
> I understand this is because i have declared it as an array. But how to get rid of this. 
>  
> 2)I face a problem when i also want to validate as float. As i/p taken is amt[1], amt[2] ... it never gets validated as float where as i want to validate individual i/p text field as float.
>  
> How can i achieve it ?
>  


Manisha - I think these messages in the archives are very similar to 
your problem.

http://www.mail-archive.com/user@struts.apache.org/msg18871.html
http://www.mail-archive.com/user@struts.apache.org/msg18895.html
http://www.mail-archive.com/user@struts.apache.org/msg18925.html

As well as this bug report:
http://issues.apache.org/bugzilla/show_bug.cgi?id=32978


Basically you can't validate each element of an array of String[] with 
the validator, because it does not have getters/setters for its value. 
Your choices are to use the validate method in the action form to do the 
validation, or to setup a new class with an amount property and 
getters/setters for the amounts, then use an array of that instead of 
String[]


Matt

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