2 Dimensional arrays?

2008-05-09 Thread Michael Gagnon
Is it possible to get back 2D arrays from a form?

 

I want to be able to have a table with some number of rows. Each row has a
'grouping' field which the user can enter a number in. Each row will also
have a dynamic 'foo' column which will have a button to add additional 'foo'
values. Some javascript will drop in new 'foo' textfields on a given row
whenever that row's button is clicked.

 

I want to be able to collect an int[] grouping array, which is straight
forward. Iterating over a collection to create textfields will let me get an
int[] in my action which will be the list of groupings indexed by row (so
grouping[0] yields the entered value for the first row, grouping[3] yields
the entered value for the fourth row, etc.)

 

I also want to be able to collect an int[][] foo array. This should be an
int[] array of foo values indexed by row. This is less straightforward and
I'm not sure how to approach this. Are there any sorts of similar examples
to this floating around?



RE: 2 Dimensional arrays?

2008-05-09 Thread Allen, Daniel
Hmm. I don't know of a way to make Struts 2 give back 2-D array
properties in the auto-magical way that it will do 1-D arrays (doesn't
mean there's not one: I keep finding out that a lot of things I want to
do can be done by magic if you know the correct XML incantation) but
perhaps you could sidestep this with JSON? I'm not particularly familiar
with AJAX stuff, but my understanding is that JSON can encode any
arbitrary object possible in JavaScript. That could potentially entail a
large number of changes, though... 

Or, another JavaScript solution, one that doesn't entail switching to
any kind of AJAX, would be to have a script that concatenates all of one
row's values into a single string, and then have a single-dimensional
array property. Sort of wasteful in that processing time is spent
composing and then parsing back to the original state, but I think it
would serve your purpose.

HTH,
~DVA

-Original Message-
From: Michael Gagnon [mailto:[EMAIL PROTECTED] 
Sent: Friday, May 09, 2008 11:36 AM
To: user@struts.apache.org
Subject: 2 Dimensional arrays?

Is it possible to get back 2D arrays from a form?

 

I want to be able to have a table with some number of rows. Each row has
a
'grouping' field which the user can enter a number in. Each row will
also
have a dynamic 'foo' column which will have a button to add additional
'foo'
values. Some javascript will drop in new 'foo' textfields on a given row
whenever that row's button is clicked.

 

I want to be able to collect an int[] grouping array, which is straight
forward. Iterating over a collection to create textfields will let me
get an
int[] in my action which will be the list of groupings indexed by row
(so
grouping[0] yields the entered value for the first row, grouping[3]
yields
the entered value for the fourth row, etc.)

 

I also want to be able to collect an int[][] foo array. This should be
an
int[] array of foo values indexed by row. This is less straightforward
and
I'm not sure how to approach this. Are there any sorts of similar
examples
to this floating around?


-- 
This message may contain confidential, proprietary, or legally privileged 
information. No confidentiality or privilege is waived by any transmission to 
an unintended recipient. If you are not an intended recipient, please notify 
the sender and delete this message immediately. Any views expressed in this 
message are those of the sender, not those of any entity within the KBC 
Financial Products group of companies (together referred to as "KBC FP"). 

This message does not create any obligation, contractual or otherwise, on the 
part of KBC FP. It is not an offer (or solicitation of an offer) of, or a 
recommendation to buy or sell, any financial product. Any prices or other 
values included in this message are indicative only, and do not necessarily 
represent current market prices, prices at which KBC FP would enter into a 
transaction, or prices at which similar transactions may be carried on KBC FP's 
own books. The information contained in this message is provided "as is", 
without representations or warranties, express or implied, of any kind. Past 
performance is not indicative of future returns.


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



RE: 2 Dimensional arrays?

2008-05-09 Thread Michael Gagnon
Thanks for the feedback. 

For lack of an accepted 'correct' solution on hand, I've gone for the
following. If anyone else is interested, it's a not-TOO-horrible solution.
The general outline looks like:




function addDataelement(id) {
var x = document.getElementById(divElement'+id);
var y = document.createElement('div');
y.setAttribute('id', 'myDiv');
y.innerHTML = '<input type="hidden" value="'+id+'"
name="dataLines" id="action_dataLines"/><input type="text" name="dataIDs"
value="1" id="action_dataIDs"/>';
x.appendChild(newdiv);
}




);">Add

">










Where my action class has:

int[] dataLines
int[] dataIDs

public void setDataLines(int[] lines)
public void setDataIDs(int[] ids)



Such that every element of dataIDs has a corresponding element in dataLines
which indicates what collection element it belongs to. This gives me the
effect of a 2D array, but does it as 2 single dimensional arrays without
departing from the struts framework. Still, this is a bit hackish, so if
anyone knows of a 'correct' way to accomplish this, I'd be happy to hear.

-Original Message-
From: Allen, Daniel [mailto:[EMAIL PROTECTED] 
Sent: Friday, May 09, 2008 1:36 PM
To: Struts Users Mailing List
Subject: RE: 2 Dimensional arrays?

Hmm. I don't know of a way to make Struts 2 give back 2-D array
properties in the auto-magical way that it will do 1-D arrays (doesn't
mean there's not one: I keep finding out that a lot of things I want to
do can be done by magic if you know the correct XML incantation) but
perhaps you could sidestep this with JSON? I'm not particularly familiar
with AJAX stuff, but my understanding is that JSON can encode any
arbitrary object possible in JavaScript. That could potentially entail a
large number of changes, though... 

Or, another JavaScript solution, one that doesn't entail switching to
any kind of AJAX, would be to have a script that concatenates all of one
row's values into a single string, and then have a single-dimensional
array property. Sort of wasteful in that processing time is spent
composing and then parsing back to the original state, but I think it
would serve your purpose.

HTH,
~DVA

-Original Message-
From: Michael Gagnon [mailto:[EMAIL PROTECTED] 
Sent: Friday, May 09, 2008 11:36 AM
To: user@struts.apache.org
Subject: 2 Dimensional arrays?

Is it possible to get back 2D arrays from a form?

 

I want to be able to have a table with some number of rows. Each row has
a
'grouping' field which the user can enter a number in. Each row will
also
have a dynamic 'foo' column which will have a button to add additional
'foo'
values. Some javascript will drop in new 'foo' textfields on a given row
whenever that row's button is clicked.

 

I want to be able to collect an int[] grouping array, which is straight
forward. Iterating over a collection to create textfields will let me
get an
int[] in my action which will be the list of groupings indexed by row
(so
grouping[0] yields the entered value for the first row, grouping[3]
yields
the entered value for the fourth row, etc.)

 

I also want to be able to collect an int[][] foo array. This should be
an
int[] array of foo values indexed by row. This is less straightforward
and
I'm not sure how to approach this. Are there any sorts of similar
examples
to this floating around?


-- 
This message may contain confidential, proprietary, or legally privileged
information. No confidentiality or privilege is waived by any transmission
to an unintended recipient. If you are not an intended recipient, please
notify the sender and delete this message immediately. Any views expressed
in this message are those of the sender, not those of any entity within the
KBC Financial Products group of companies (together referred to as "KBC
FP"). 

This message does not create any obligation, contractual or otherwise, on
the part of KBC FP. It is not an offer (or solicitation of an offer) of, or
a recommendation to buy or sell, any financial product. Any prices or other
values included in this message are indicative only, and do not necessarily
represent current market prices, prices at which KBC FP would enter into a
transaction, or prices at which similar transactions may be carried on KBC
FP's own books. The information contained in this message is provided "as
is", without representations or warranties, express or implied, of any kind.
Past performance is not indicative of future returns.


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




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



2 deep nested forms (solution to 2 dimensional arrays with struts html tags)

2004-06-24 Thread Mark Lowe
A question came up the other week/month where someone nesting 2 deep 
and was trying to use a 2 dimesional array. I had the some problem 
today and had my chance to combine indexed and mapped properties to 
solve the problem.

I want to create a Restaurant Menu editor. So a menu has a few 
properties like title and start and end dates for seasonal menus.

So I have 3 action form or nested pojo's
MenuForm
CourseForm
DishBean
I used lazyMap and lazyList to save scoping to session.
MenuForm - has a lazyList or nested courses.
CourseForm - has a lazyMap of dishes and a getKeys() method that 
returns map.keySet().toArray()

and dishes are just plain string properties.
public DishBean getDish(String key)
public void setDish(String key,DishBean dish)
The jsp stuff looks something like this.


	
	
	
		
	


its not quite as tidy as 2 dimensional array support, but it pretty 
clean looking.


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


Re: 2 deep nested forms (solution to 2 dimensional arrays with struts html tags)

2004-06-24 Thread Mark Lowe
Not quite.. hang on.

On 25 Jun 2004, at 00:14, Mark Lowe wrote:
A question came up the other week/month where someone nesting 2 deep 
and was trying to use a 2 dimesional array. I had the some problem 
today and had my chance to combine indexed and mapped properties to 
solve the problem.

I want to create a Restaurant Menu editor. So a menu has a few 
properties like title and start and end dates for seasonal menus.

So I have 3 action form or nested pojo's
MenuForm
CourseForm
DishBean
I used lazyMap and lazyList to save scoping to session.
MenuForm - has a lazyList or nested courses.
CourseForm - has a lazyMap of dishes and a getKeys() method that 
returns map.keySet().toArray()

and dishes are just plain string properties.
public DishBean getDish(String key)
public void setDish(String key,DishBean dish)
The jsp stuff looks something like this.


	
	
	
		
	


its not quite as tidy as 2 dimensional array support, but it pretty 
clean looking.


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

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


Re: 2 deep nested forms (solution to 2 dimensional arrays with struts html tags)

2004-06-24 Thread Mark Lowe
No needs a rethink .
indexed="true" uses whatever iteration tags that its between.. Arses,, 
drat and double drat.


On 25 Jun 2004, at 00:27, Mark Lowe wrote:
Not quite.. hang on.

On 25 Jun 2004, at 00:14, Mark Lowe wrote:
A question came up the other week/month where someone nesting 2 deep 
and was trying to use a 2 dimesional array. I had the some problem 
today and had my chance to combine indexed and mapped properties to 
solve the problem.

I want to create a Restaurant Menu editor. So a menu has a few 
properties like title and start and end dates for seasonal menus.

So I have 3 action form or nested pojo's
MenuForm
CourseForm
DishBean
I used lazyMap and lazyList to save scoping to session.
MenuForm - has a lazyList or nested courses.
CourseForm - has a lazyMap of dishes and a getKeys() method that 
returns map.keySet().toArray()

and dishes are just plain string properties.
public DishBean getDish(String key)
public void setDish(String key,DishBean dish)
The jsp stuff looks something like this.


	
	
	
		
	


its not quite as tidy as 2 dimensional array support, but it pretty 
clean looking.


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

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

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


Re: 2 deep nested forms (solution to 2 dimensional arrays with struts html tags)

2004-06-25 Thread Mark Lowe
No i was wrong works as i thought it would
Need to iterate through the values of the dishes map
public Object[] getDishes() {
return map.values().toArray();
}
<%-- var could be anything the index us the important bit --%>

<%-- get the correctly indexed key from the getKeys array-%>



renders to


On 25 Jun 2004, at 01:09, Mark Lowe wrote:
No needs a rethink .
indexed="true" uses whatever iteration tags that its between.. Arses,, 
drat and double drat.


On 25 Jun 2004, at 00:27, Mark Lowe wrote:
Not quite.. hang on.

On 25 Jun 2004, at 00:14, Mark Lowe wrote:
A question came up the other week/month where someone nesting 2 deep 
and was trying to use a 2 dimesional array. I had the some problem 
today and had my chance to combine indexed and mapped properties to 
solve the problem.

I want to create a Restaurant Menu editor. So a menu has a few 
properties like title and start and end dates for seasonal menus.

So I have 3 action form or nested pojo's
MenuForm
CourseForm
DishBean
I used lazyMap and lazyList to save scoping to session.
MenuForm - has a lazyList or nested courses.
CourseForm - has a lazyMap of dishes and a getKeys() method that 
returns map.keySet().toArray()

and dishes are just plain string properties.
public DishBean getDish(String key)
public void setDish(String key,DishBean dish)
The jsp stuff looks something like this.


	
	
	
		
	


its not quite as tidy as 2 dimensional array support, but it pretty 
clean looking.


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

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

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

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


AW: 2 deep nested forms (solution to 2 dimensional arrays with struts html tags)

2004-06-25 Thread René Zbinden
I'm not sure if i got the problem correctly. But have a look at the nested taglib too. 
Could make your jsp easier but renders to the same as below. 
http://jakarta.apache.org/struts/userGuide/struts-nested.html

http://www.keyboardmonkey.com/next/index.jsp

Hope it's of any use to you
René


-Ursprüngliche Nachricht-
Von: Mark Lowe [mailto:[EMAIL PROTECTED] 
Gesendet: Freitag, 25. Juni 2004 09:33
An: Struts Users Mailing List
Betreff: Re: 2 deep nested forms (solution to 2 dimensional arrays with struts html 
tags)

No i was wrong works as i thought it would

Need to iterate through the values of the dishes map

public Object[] getDishes() {
return map.values().toArray();
}


<%-- var could be anything the index us the important bit --%> 
<%-- get the correctly indexed key from the getKeys array-%>   

renders to






On 25 Jun 2004, at 01:09, Mark Lowe wrote:

> No needs a rethink .
>
> indexed="true" uses whatever iteration tags that its between.. Arses,, 
> drat and double drat.
>
>
>
> On 25 Jun 2004, at 00:27, Mark Lowe wrote:
>
>> Not quite.. hang on.
>>
>>
>>
>> On 25 Jun 2004, at 00:14, Mark Lowe wrote:
>>
>>> A question came up the other week/month where someone nesting 2 deep 
>>> and was trying to use a 2 dimesional array. I had the some problem 
>>> today and had my chance to combine indexed and mapped properties to 
>>> solve the problem.
>>>
>>> I want to create a Restaurant Menu editor. So a menu has a few 
>>> properties like title and start and end dates for seasonal menus.
>>>
>>> So I have 3 action form or nested pojo's
>>>
>>>
>>> MenuForm
>>> CourseForm
>>> DishBean
>>>
>>> I used lazyMap and lazyList to save scoping to session.
>>>
>>>
>>> MenuForm - has a lazyList or nested courses.
>>> CourseForm - has a lazyMap of dishes and a getKeys() method that 
>>> returns map.keySet().toArray()
>>>
>>> and dishes are just plain string properties.
>>>
>>> public DishBean getDish(String key)
>>>
>>> public void setDish(String key,DishBean dish)
>>>
>>> The jsp stuff looks something like this.
>>>
>>> 
>>>
>>> 
>>> 
>>> 
>>> 
>>> >> indexed="true" />
>>> 
>>>
>>> 
>>>
>>> its not quite as tidy as 2 dimensional array support, but it pretty 
>>> clean looking.
>>>
>>>
>>>
>>> 
>>> - To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>
>>
>> -
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


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



Re: AW: 2 deep nested forms (solution to 2 dimensional arrays with struts html tags)

2004-06-25 Thread Mark Lowe
I haven't played with netsted tags for a while, I always preferred 
seeing where in indexed properties were. I have to confess it 
completely escaped my attention.

Mark
On 25 Jun 2004, at 13:55, René Zbinden wrote:
I'm not sure if i got the problem correctly. But have a look at the 
nested taglib too. Could make your jsp easier but renders to the same 
as below.
http://jakarta.apache.org/struts/userGuide/struts-nested.html

http://www.keyboardmonkey.com/next/index.jsp
Hope it's of any use to you
René
-Ursprüngliche Nachricht-
Von: Mark Lowe [mailto:[EMAIL PROTECTED]
Gesendet: Freitag, 25. Juni 2004 09:33
An: Struts Users Mailing List
Betreff: Re: 2 deep nested forms (solution to 2 dimensional arrays 
with struts html tags)

No i was wrong works as i thought it would
Need to iterate through the values of the dishes map
public Object[] getDishes() {
return map.values().toArray();
}
<%-- var could be anything the index us the important bit --%> 

<%-- get the correctly indexed key from the getKeys array-%>   


renders to


On 25 Jun 2004, at 01:09, Mark Lowe wrote:
No needs a rethink .
indexed="true" uses whatever iteration tags that its between.. Arses,,
drat and double drat.

On 25 Jun 2004, at 00:27, Mark Lowe wrote:
Not quite.. hang on.

On 25 Jun 2004, at 00:14, Mark Lowe wrote:
A question came up the other week/month where someone nesting 2 deep
and was trying to use a 2 dimesional array. I had the some problem
today and had my chance to combine indexed and mapped properties to
solve the problem.
I want to create a Restaurant Menu editor. So a menu has a few
properties like title and start and end dates for seasonal menus.
So I have 3 action form or nested pojo's
MenuForm
CourseForm
DishBean
I used lazyMap and lazyList to save scoping to session.
MenuForm - has a lazyList or nested courses.
CourseForm - has a lazyMap of dishes and a getKeys() method that
returns map.keySet().toArray()
and dishes are just plain string properties.
public DishBean getDish(String key)
public void setDish(String key,DishBean dish)
The jsp stuff looks something like this.








its not quite as tidy as 2 dimensional array support, but it pretty
clean looking.


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

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

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

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


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


Re: AW: 2 deep nested forms (solution to 2 dimensional arrays with struts html tags)

2004-06-25 Thread Mark Lowe
Sat under my nose all the time :o)

On 25 Jun 2004, at 15:06, Mark Lowe wrote:
I haven't played with netsted tags for a while, I always preferred  
seeing where in indexed properties were. I have to confess it  
completely escaped my attention.

Mark
On 25 Jun 2004, at 13:55, René Zbinden wrote:
I'm not sure if i got the problem correctly. But have a look at the  
nested taglib too. Could make your jsp easier but renders to the same  
as below.
http://jakarta.apache.org/struts/userGuide/struts-nested.html

http://www.keyboardmonkey.com/next/index.jsp
Hope it's of any use to you
René
-Ursprüngliche Nachricht-
Von: Mark Lowe [mailto:[EMAIL PROTECTED]
Gesendet: Freitag, 25. Juni 2004 09:33
An: Struts Users Mailing List
Betreff: Re: 2 deep nested forms (solution to 2 dimensional arrays  
with struts html tags)

No i was wrong works as i thought it would
Need to iterate through the values of the dishes map
public Object[] getDishes() {
return map.values().toArray();
}
<%-- var could be anything the index us the important bit --%>  

<%-- get the correctly indexed key from the getKeys array-%>


renders to


On 25 Jun 2004, at 01:09, Mark Lowe wrote:
No needs a rethink .
indexed="true" uses whatever iteration tags that its between..  
Arses,,
drat and double drat.


On 25 Jun 2004, at 00:27, Mark Lowe wrote:
Not quite.. hang on.

On 25 Jun 2004, at 00:14, Mark Lowe wrote:
A question came up the other week/month where someone nesting 2  
deep
and was trying to use a 2 dimesional array. I had the some problem
today and had my chance to combine indexed and mapped properties to
solve the problem.

I want to create a Restaurant Menu editor. So a menu has a few
properties like title and start and end dates for seasonal menus.
So I have 3 action form or nested pojo's
MenuForm
CourseForm
DishBean
I used lazyMap and lazyList to save scoping to session.
MenuForm - has a lazyList or nested courses.
CourseForm - has a lazyMap of dishes and a getKeys() method that
returns map.keySet().toArray()
and dishes are just plain string properties.
public DishBean getDish(String key)
public void setDish(String key,DishBean dish)
The jsp stuff looks something like this.








its not quite as tidy as 2 dimensional array support, but it pretty
clean looking.

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


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


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

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


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


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