You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rajat Pandit <ra...@centergroupinc.com> on 2003/10/26 16:54:41 UTC

Indexed properties help!

Hello,
I am pasting some excepts from the struts documentation. It would be
really great if someone could help me clear this.

Question 1:
<!-- snip -->
 The "indexed tags" feature is provided by several tags that have an
optional boolean "indexed" attribute. This is only legal when inside a
"<logic:iterate>" tag. When the "indexed" attribute is true, then the
tag will incorporate the loop index into the resulting HTML component.

The several tags that support the "indexed" attribute can be broken into
three groups, split by what they do to incorporate the loop index into
the resulting HTML component.
Group 1	Group 2	Group 3
checkbox	button	link
file	image	 
hidden	submit	 
password	 	 
radio	 	 
select	 	 
text	 	 
textarea	 	 

In Group 1, all of these tags will generate an HTML "name" attribute of
"name[nn].property". The value of each tag will also be initialized by
the getter method corresponding to that property specification. 
<!--snip -->


So if I have name[nn].property, that essentially means I am creating an
array of the form. But what I really need is an array of property,
instead of the bean.

Question 2:

How should the property be declared in the the actionForm if it has to
receive an array of information.


thanks




Rajat Pandit | rajatp@centergroupinc.com
+91 612 3117606
[ Developer and Part Time Human Being]


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


RE: Indexed properties help!

Posted by Frederic Dernbach <fr...@free.fr>.
Looks OK.

However, I would not use a basic array  (private members) but ArrayList,
HashMap or LinkedList, etc.

I did not manage to have arrays working (the lazy initialization
failed).

You will have problems in JSPs.


Le dim 26/10/2003 à 18:04, Rajat Pandit a écrit :
> Hello fred,
> Thanks for the  reply, so just for clarifiation, if I am using a
> property which will be "indexed" then the getters and setters will be a
> little different from the usual set and get
> Ie
> 
> public String getBidAmount(int index) {
> 	return bidAmount[index];
> }
> 
> And 
> public  void setBidAmount(int index, String val) {
> 	bidAmount[index] = val;
> }
> 
> And have to implement the bidAmoutn as an array?
> Protected String[] bidAmount;
> 
> Do confirm if igot that right?
> Thanks once again for ur time.
> 
> 
> -----Original Message-----
> From: Frederic Dernbach [mailto:fredatwork@free.fr] 
> Sent: Sunday, October 26, 2003 8:23 AM
> To: Struts Users Mailing List
> Subject: Re: Indexed properties help!
> 
> 
> Rajat,
> 
> Here is an example of an indexed property called 'signal' (in my
> application it holds complex objects, not simple strings or integers):
> 
> 	public OrderedSignalBean getSignal(int index) {
> 		while( index >= this.getSignals().size() ){
> 			this.getSignals().add(new OrderedSignalBean());
> 		}
> 		return (OrderedSignalBean) this.getSignals().get(index);
> 	}
> 
> 	public void setSignal(int index, OrderedSignalBean signal) {
> 		while ( index >= signals.size() ){
> 			signals.add(new OrderedSignalBean());
> 		}
> 		signals.set(index, signal);
> 	}
> 
> The 'signals' member is private and is of type 'ArrayList'. It is
> created in the form's contructor and the reset method of the form :
> signals = new ArrayList().
> 
> The setter and getter methods of the indexed property perform so-clled
> "lazy-initialization" so you do not have to worry about the siez of the
> array list.
> 
> Hope this helps.
> 
> Fred 
> 
> 
> Le dim 26/10/2003 à 16:54, Rajat Pandit a écrit :
> > Hello,
> > I am pasting some excepts from the struts documentation. It would be 
> > really great if someone could help me clear this.
> > 
> > Question 1:
> > <!-- snip -->
> >  The "indexed tags" feature is provided by several tags that have an 
> > optional boolean "indexed" attribute. This is only legal when inside a
> 
> > "<logic:iterate>" tag. When the "indexed" attribute is true, then the 
> > tag will incorporate the loop index into the resulting HTML component.
> > 
> > The several tags that support the "indexed" attribute can be broken 
> > into three groups, split by what they do to incorporate the loop index
> 
> > into the resulting HTML component.
> > Group 1	Group 2	Group 3
> > checkbox	button	link
> > file	image	 
> > hidden	submit	 
> > password	 	 
> > radio	 	 
> > select	 	 
> > text	 	 
> > textarea	 	 
> > 
> > In Group 1, all of these tags will generate an HTML "name" attribute 
> > of "name[nn].property". The value of each tag will also be initialized
> 
> > by the getter method corresponding to that property specification. 
> > <!--snip -->
> > 
> > 
> > So if I have name[nn].property, that essentially means I am creating 
> > an array of the form. But what I really need is an array of property, 
> > instead of the bean.
> > 
> > Question 2:
> > 
> > How should the property be declared in the the actionForm if it has to
> 
> > receive an array of information.
> > 
> > 
> > thanks
> > 
> > 
> > 
> > 
> > Rajat Pandit | rajatp@centergroupinc.com
> > +91 612 3117606
> > [ Developer and Part Time Human Being]
> > 
> > 
> > ---------------------------------------------------------------------
> > 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
> 
> 
> ---------------------------------------------------------------------
> 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


RE: Indexed properties help!

Posted by Rajat Pandit <ra...@centergroupinc.com>.
Hello fred,
Thanks for the  reply, so just for clarifiation, if I am using a
property which will be "indexed" then the getters and setters will be a
little different from the usual set and get
Ie

public String getBidAmount(int index) {
	return bidAmount[index];
}

And 
public  void setBidAmount(int index, String val) {
	bidAmount[index] = val;
}

And have to implement the bidAmoutn as an array?
Protected String[] bidAmount;

Do confirm if igot that right?
Thanks once again for ur time.


-----Original Message-----
From: Frederic Dernbach [mailto:fredatwork@free.fr] 
Sent: Sunday, October 26, 2003 8:23 AM
To: Struts Users Mailing List
Subject: Re: Indexed properties help!


Rajat,

Here is an example of an indexed property called 'signal' (in my
application it holds complex objects, not simple strings or integers):

	public OrderedSignalBean getSignal(int index) {
		while( index >= this.getSignals().size() ){
			this.getSignals().add(new OrderedSignalBean());
		}
		return (OrderedSignalBean) this.getSignals().get(index);
	}

	public void setSignal(int index, OrderedSignalBean signal) {
		while ( index >= signals.size() ){
			signals.add(new OrderedSignalBean());
		}
		signals.set(index, signal);
	}

The 'signals' member is private and is of type 'ArrayList'. It is
created in the form's contructor and the reset method of the form :
signals = new ArrayList().

The setter and getter methods of the indexed property perform so-clled
"lazy-initialization" so you do not have to worry about the siez of the
array list.

Hope this helps.

Fred 


Le dim 26/10/2003 à 16:54, Rajat Pandit a écrit :
> Hello,
> I am pasting some excepts from the struts documentation. It would be 
> really great if someone could help me clear this.
> 
> Question 1:
> <!-- snip -->
>  The "indexed tags" feature is provided by several tags that have an 
> optional boolean "indexed" attribute. This is only legal when inside a

> "<logic:iterate>" tag. When the "indexed" attribute is true, then the 
> tag will incorporate the loop index into the resulting HTML component.
> 
> The several tags that support the "indexed" attribute can be broken 
> into three groups, split by what they do to incorporate the loop index

> into the resulting HTML component.
> Group 1	Group 2	Group 3
> checkbox	button	link
> file	image	 
> hidden	submit	 
> password	 	 
> radio	 	 
> select	 	 
> text	 	 
> textarea	 	 
> 
> In Group 1, all of these tags will generate an HTML "name" attribute 
> of "name[nn].property". The value of each tag will also be initialized

> by the getter method corresponding to that property specification. 
> <!--snip -->
> 
> 
> So if I have name[nn].property, that essentially means I am creating 
> an array of the form. But what I really need is an array of property, 
> instead of the bean.
> 
> Question 2:
> 
> How should the property be declared in the the actionForm if it has to

> receive an array of information.
> 
> 
> thanks
> 
> 
> 
> 
> Rajat Pandit | rajatp@centergroupinc.com
> +91 612 3117606
> [ Developer and Part Time Human Being]
> 
> 
> ---------------------------------------------------------------------
> 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


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


Re: Indexed properties help!

Posted by Frederic Dernbach <fr...@free.fr>.
Rajat,

Here is an example of an indexed property called 'signal' (in my
application it holds complex objects, not simple strings or integers):

	public OrderedSignalBean getSignal(int index) {
		while( index >= this.getSignals().size() ){
			this.getSignals().add(new OrderedSignalBean());
		}
		return (OrderedSignalBean) this.getSignals().get(index);
	}

	public void setSignal(int index, OrderedSignalBean signal) {
		while ( index >= signals.size() ){
			signals.add(new OrderedSignalBean());
		}
		signals.set(index, signal);
	}

The 'signals' member is private and is of type 'ArrayList'. It is
created in the form's contructor and the reset method of the form :
signals = new ArrayList().

The setter and getter methods of the indexed property perform so-clled
"lazy-initialization" so you do not have to worry about the siez of the
array list.

Hope this helps.

Fred 


Le dim 26/10/2003 à 16:54, Rajat Pandit a écrit :
> Hello,
> I am pasting some excepts from the struts documentation. It would be
> really great if someone could help me clear this.
> 
> Question 1:
> <!-- snip -->
>  The "indexed tags" feature is provided by several tags that have an
> optional boolean "indexed" attribute. This is only legal when inside a
> "<logic:iterate>" tag. When the "indexed" attribute is true, then the
> tag will incorporate the loop index into the resulting HTML component.
> 
> The several tags that support the "indexed" attribute can be broken into
> three groups, split by what they do to incorporate the loop index into
> the resulting HTML component.
> Group 1	Group 2	Group 3
> checkbox	button	link
> file	image	 
> hidden	submit	 
> password	 	 
> radio	 	 
> select	 	 
> text	 	 
> textarea	 	 
> 
> In Group 1, all of these tags will generate an HTML "name" attribute of
> "name[nn].property". The value of each tag will also be initialized by
> the getter method corresponding to that property specification. 
> <!--snip -->
> 
> 
> So if I have name[nn].property, that essentially means I am creating an
> array of the form. But what I really need is an array of property,
> instead of the bean.
> 
> Question 2:
> 
> How should the property be declared in the the actionForm if it has to
> receive an array of information.
> 
> 
> thanks
> 
> 
> 
> 
> Rajat Pandit | rajatp@centergroupinc.com
> +91 612 3117606
> [ Developer and Part Time Human Being]
> 
> 
> ---------------------------------------------------------------------
> 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