Indexed Properties. Maintaining Order

2006-09-21 Thread Puneet Lakhina

Hi,
I have a no. of fields in a form arranged in a table of rows. I am using
indexed properties for these fields. The number of these fields isn't known
to me at the time of page loading for which I have used some DHTML to
properly add the fields. And all the values are getting submitted.
Now my problem is that the order is getting jumbled up.

My table is like this

No.   Date   Description
1.  date[0]description[0]
2.   date[1]description[1]

But after submitting, the order gets jumbled up. i.e. i get something like
this

No.   Date   Description
1.  date[0]description[1]
2.   date[1]description[0]

This I have figured is because of the following setter methods

public void setDate(int index,String value) {
datesList.add(value);
}

public void setDescription(int index,String value) {
descriptionsList.add(value);
}

So basically the order in which the setter methods are called is random. i.e.
setDate(0,value) -   setDescription(1,value)  and so on.
Does this problem mean we have no way of maintaining order when using lists?


What I have thought of is instead of using Indexed Properties I will use
map backed properties. But if somebody can offer me some sort of solution
that doesn't require change from Lists to Map it would be great.


--
Puneet


Re: Indexed Properties. Maintaining Order

2006-09-21 Thread Niall Pemberton

As you found out there is no way of knowing the order the
browser/client will submit request parameters, so if you want to use
indexed properties in this way you need to grow the list to
accomodate the size of the indexed property being set.

So you could do something like the following:

 public void setDate(int index,String value) {
 while (datesList.size() = index) {
 datesList.add(null);
  }
 datesList.set(index, value);
 }

This is what LazyDynaBean / LazyDynaForm does:

http://struts.apache.org/1.x/userGuide/building_controller.html#lazy_action_form_classes

Theres also this page on the wiki:
http://wiki.apache.org/struts/StrutsCatalogLazyList

Niall

On 9/21/06, Puneet Lakhina [EMAIL PROTECTED] wrote:

Hi,
I have a no. of fields in a form arranged in a table of rows. I am using
indexed properties for these fields. The number of these fields isn't known
to me at the time of page loading for which I have used some DHTML to
properly add the fields. And all the values are getting submitted.
Now my problem is that the order is getting jumbled up.

My table is like this

No.   Date   Description
1.  date[0]description[0]
2.   date[1]description[1]

But after submitting, the order gets jumbled up. i.e. i get something like
this

No.   Date   Description
1.  date[0]description[1]
2.   date[1]description[0]

This I have figured is because of the following setter methods

public void setDate(int index,String value) {
datesList.add(value);
}

public void setDescription(int index,String value) {
descriptionsList.add(value);
}

So basically the order in which the setter methods are called is random. i.e.
setDate(0,value) -   setDescription(1,value)  and so on.
Does this problem mean we have no way of maintaining order when using lists?


What I have thought of is instead of using Indexed Properties I will use
map backed properties. But if somebody can offer me some sort of solution
that doesn't require change from Lists to Map it would be great.


--
Puneet




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



RE: Indexed Properties. Maintaining Order

2006-09-21 Thread Strachan, Paul
A List is an ordered collection so it doesnt make sense that the order changes. 
 Also, depending on which Map implementation you use ordering may not be 
guaranteed.  I frequently use indexed properties with List and have not 
experienced this problem.  You may need to check the generated html source and 
follow through the request cycle.
 
Your method signatures for your setters dont seem appropriate in the context of 
managing indexed properties on a list of objects (at least to me).  Perhaps you 
are managing your indexed properties in a way that would better suit a Map 
implementation, but I cant tell from the provided code.



From: Puneet Lakhina [mailto:[EMAIL PROTECTED]
Sent: Thu 21/09/2006 7:43 PM
To: Struts Users Mailing List
Subject: Indexed Properties. Maintaining Order



Hi,
I have a no. of fields in a form arranged in a table of rows. I am using
indexed properties for these fields. The number of these fields isn't known
to me at the time of page loading for which I have used some DHTML to
properly add the fields. And all the values are getting submitted.
Now my problem is that the order is getting jumbled up.

My table is like this

No.   Date   Description
1.  date[0]description[0]
2.   date[1]description[1]

But after submitting, the order gets jumbled up. i.e. i get something like
this

No.   Date   Description
1.  date[0]description[1]
2.   date[1]description[0]

This I have figured is because of the following setter methods

public void setDate(int index,String value) {
datesList.add(value);
}

public void setDescription(int index,String value) {
descriptionsList.add(value);
}

So basically the order in which the setter methods are called is random. i.e.
setDate(0,value) -   setDescription(1,value)  and so on.
Does this problem mean we have no way of maintaining order when using lists?


What I have thought of is instead of using Indexed Properties I will use
map backed properties. But if somebody can offer me some sort of solution
that doesn't require change from Lists to Map it would be great.


--
Puneet


**
This message is intended for the addressee named and may contain
privileged information or confidential information or both. If you
are not the intended recipient please delete it and notify the sender.
**

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



Re: Indexed Properties. Maintaining Order

2006-09-21 Thread Puneet Lakhina

On 9/21/06, Strachan, Paul [EMAIL PROTECTED] wrote:


A List is an ordered collection so it doesnt make sense that the order
changes.  Also, depending on which Map implementation you use ordering may
not be guaranteed.



I would basically have the index in case of indexed properties as my key. SO
the question of ordering doest come
publiv void setDate(String key, String value) {
map.put(key,value);
}
This way I would always have the correct values.

I frequently use indexed properties with List and have not experienced this

problem.  You may need to check the generated html source and follow through
the request cycle.

Your method signatures for your setters dont seem appropriate in the
context of managing indexed properties on a list of objects (at least to
me).



Could you please give an example of how you manage lists with indexed
properties, that would really help.

Thanks
--
Puneet


Re: Indexed Properties. Maintaining Order

2006-09-21 Thread Puneet Lakhina

On 9/21/06, Niall Pemberton [EMAIL PROTECTED] wrote:


As you found out there is no way of knowing the order the
browser/client will submit request parameters, so if you want to use
indexed properties in this way you need to grow the list to
accomodate the size of the indexed property being set.

So you could do something like the following:

  public void setDate(int index,String value) {
  while (datesList.size() = index) {
  datesList.add(null);
   }
  datesList.set(index, value);
  }



I  kinda did this before posting as a temp fix. But I though this was like a
too inefficinet solution. But Im glad it isnt all that bad a thing :-).

Thanks a lot.
--
Puneet


RE: Indexed Properties. Maintaining Order

2006-09-21 Thread Strachan, Paul
Hi Puneet,

When I re-read your original mail I notice you use DHTML to add rows, so
my approach/thoughts may not be appropriate for you. 

I use DynaForms with ArrayLists of objects. In the form I use the
logic:iterate with indexed=true on the html tags. If I need to
dynamically add another row I do a submit (no validate) and simply add
an empty object into my List and forward back to the page.


On 9/22/06, Puneet Lakhina [mailto:[EMAIL PROTECTED] wrote:

 Could you please give an example of how you manage lists with indexed
 properties, that would really help.
 
 Thanks
 -- 
 Puneet
**
This message is intended for the addressee named and may contain
privileged information or confidential information or both. If you
are not the intended recipient please delete it and notify the sender.
**

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