You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by bi...@tcs.com on 2004/06/01 16:05:00 UTC

Problem with Dynamic text boxes

hi
 i have to display a screen in which the no of rows are dynamic. in each 
row there are 2 text boxes where user can enter values.
 after entering the values in the text boxes user press 'SAVE'  button . 
in the Action form  i have to validate the values in the validate() method 
. also 
in the Action class  there will be some data processing. 

but how can i use get(),set() methods of the Action form,as the no of rows 
are not fixed.

i am trying to avoid the request.getParameter('Field name'); in the Action 
form or in Action Class.


Any Suggestion! 

Thanks

Biswajit Basak

Re: Problem with Dynamic text boxes

Posted by David Erickson <de...@cmcflex.com>.
You might also want to use indexed properties.
Look into the indexed=true flag on the html taglibs.
-David

----- Original Message ----- 
From: "sean jones" <se...@ubs.com>
To: <us...@struts.apache.org>
Sent: Tuesday, June 01, 2004 8:29 AM
Subject: Re: Problem with Dynamic text boxes


> <biswajit.basak <at> tcs.com> writes:
>
> >
> >
> > hi i have to display a screen in
> > which the no of rows are dynamic. in each row there are 2 text boxes
where
> > user can enter values. after entering the values in the
> > text boxes user press 'SAVE' button . in the Action form i
> > have to validate the values in the validate() method . also in the
Action
> class there will
> > be some data processing. but how can i use get(),set() methods
> > of the Action form,as the no of rows are not fixed.i am trying to avoid
the
> request.getParameter('Field
> > name'); in the Action form or in Action Class.Any Suggestion! Thanks
> > Biswajit Basak
> >
>
> in your action form you can do this.
>
> String text1[];
> string text2[];
>
> public void setText1(String text[]) text1 = text; }
> public void setText2(String text[]) text2 = text; }
> public String getText1() {return text1; }
> public String getText2() {return text2; }
>
>
> validate() {
>
> if (text1.length != text2.length) {
> //save this error here.
> }
> else {
>    //loop through arrays validating each pair.
>    //and saving appropriate errors.
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


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


Re: Problem with Dynamic text boxes

Posted by sean jones <se...@ubs.com>.
 <biswajit.basak <at> tcs.com> writes:

> 
> 
> hi i have to display a screen in
> which the no of rows are dynamic. in each row there are 2 text boxes where
> user can enter values. after entering the values in the
> text boxes user press 'SAVE'  button .  in the Action form  i
> have to validate the values in the validate() method . also in the Action 
class  there will
> be some data processing. but how can i use get(),set() methods
> of the Action form,as the no of rows are not fixed.i am trying to avoid the 
request.getParameter('Field
> name'); in the Action form or in Action Class.Any Suggestion! Thanks
> Biswajit Basak
> 

in your action form you can do this.

String text1[];
string text2[];

public void setText1(String text[]) text1 = text; }
public void setText2(String text[]) text2 = text; }
public String getText1() {return text1; }
public String getText2() {return text2; }


validate() {

if (text1.length != text2.length) {
//save this error here.
}
else {
   //loop through arrays validating each pair.
   //and saving appropriate errors. 
}



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


Re: Problem with Dynamic text boxes

Posted by Rick Reumann <st...@reumann.net>.
biswajit.basak@tcs.com wrote:

>  i have to display a screen in which the no of rows are dynamic. in each 
> row there are 2 text boxes where user can enter values.
>  after entering the values in the text boxes user press 'SAVE'  button . 
>  in the Action form  i have to validate the values in the validate() 
> method . also
> in the Action class  there will be some data processing.
> 
> but how can i use get(),set() methods of the Action form,as the no of 
> rows are not fixed.

Your form should take a Collection or an array of beans.. where each 
bean then has the text fields you are concerned with. (ie SomeBean would 
have get/set methods for the two text names). Think of each row 
reprenting a bean.

Then you just loop over the Collection, pull out the bean each time and 
create your two text fields. When you submit Struts will automagically 
populate all your beans correctly.

-- 
Rick

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