You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Damien SAUVAGEOT <ds...@omnikles.com> on 2004/07/09 17:12:45 UTC
Form with n columns and m raws
Hello,
I can't find how to implement a form which include n*m checkbox.
I would like to get :
doc1 doc2 doc3 ... docn
client1 x x x
client2 x x x
client 3 x x x
...
client m x x x x
I managed to get the form but I can't retrieve the values in the validate function
private String[][] enveloppes;
in reset :
enveloppes = new String[n][m];
for(int i = 0; i < m; i++) {
for (int j=0; j < n; j++) {
enveloppes[j][i] = "off";
}
}
and for example, i get an array of 2*10 elements.
but when I check the size of enveloppes into the validate function, I get a strange size of 1*1.
There is also the getter/setter :
/**
* @return Returns the enveloppes.
*/
public String[][] getEnveloppes() {
return enveloppes;
}
/**
* @param enveloppes The enveloppes to set.
*/
public void setEnveloppes(String[][] enveloppes) {
this.enveloppes = enveloppes;
}
Does anyone know the reason why the enveloppe size isn't 2*10?
I tried to log a lot of stuff and was not able to determine anything. The setter is apparently never called.
I guess Struts is in charge of populating the form when it is sent back by the browser.
I managed to use array of 1 dimension with struts form, even if I had quite a hard time to figure out how to make it works but
I can't find any solution for 2 dimensions arrays.
the generated html corresponding parts are :
...
<td><input type="checkbox" name="enveloppes[0][7]" value="on"></td>
<td><input type="checkbox" name="enveloppes[1][7]" value="on"></td>
<td><input type="checkbox" name="enveloppes[0][8]" value="on"></td>
<td><input type="checkbox" name="enveloppes[1][8]" value="on"></td>
...
Thanks for the help,
Damien
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Form with n columns and m raws
Posted by atta-ur rehman <at...@numetrics.com>.
Hello Damien,
have a new class called row:
public class Row {
private List items;
public Row(int size, String defaultValue) {
items = new ArrayList(size);
for (int i = 0; i < size; i++) {
items.add(defaultValue);
}
}
public Row(int size) {
this(size, "");
}
public List getItems() {
return items;
}
public void setItems(List items) {
this.items = items;
}
public int size() {
return items.size();
}
}
----------------------------------------------------------------------------
----------------------------
now in your ActionForm class:
public List getDemandGrid() {
return demandGrid;
}
public void setDemandGrid(List list) {
demandGrid = list;
}
----------------------------------------------------------------------------
----------------------------
in your action class setup the initial grid:
List demandGrid = new ArrayList(demandCount);
for (int i = 0; i < ?; i++) {
demandRow = new Row(quarters.size(), "OFF");
demandGrid.add(deamndRow);
}
form.setDemandGrid(demandGrid);
----------------------------------------------------------------------------
----------------------------
in your jsp:
<%
height = businessRevForecastForm.getDemandGrid().size();
width = ((Row) businessRevForecastForm.getDemandGrid().get(0)).size();
grid = businessRevForecastForm.getDemandGrid();
%>
<% for (int y = 0; y < height; y++) { %>
<tr>
<% for (int x = 0; x < width; x++) { %>
<td><html:text property='<%= "demandGrid["+y+"].items["+x+"]" %>'
size="7"/></td>
<% } %>
</tr>
<% } %>
after submit, form.getDemandGrid() list should be populated!
hope this helps.
ATTA
----- Original Message -----
From: "Damien SAUVAGEOT" <ds...@omnikles.com>
To: <us...@struts.apache.org>
Sent: Friday, July 09, 2004 8:12 AM
Subject: Form with n columns and m raws
Hello,
I can't find how to implement a form which include n*m checkbox.
I would like to get :
doc1 doc2 doc3 ... docn
client1 x x x
client2 x x x
client 3 x x x
...
client m x x x x
I managed to get the form but I can't retrieve the values in the validate
function
private String[][] enveloppes;
in reset :
enveloppes = new String[n][m];
for(int i = 0; i < m; i++) {
for (int j=0; j < n; j++) {
enveloppes[j][i] = "off";
}
}
and for example, i get an array of 2*10 elements.
but when I check the size of enveloppes into the validate function, I get a
strange size of 1*1.
There is also the getter/setter :
/**
* @return Returns the enveloppes.
*/
public String[][] getEnveloppes() {
return enveloppes;
}
/**
* @param enveloppes The enveloppes to set.
*/
public void setEnveloppes(String[][] enveloppes) {
this.enveloppes = enveloppes;
}
Does anyone know the reason why the enveloppe size isn't 2*10?
I tried to log a lot of stuff and was not able to determine anything. The
setter is apparently never called.
I guess Struts is in charge of populating the form when it is sent back by
the browser.
I managed to use array of 1 dimension with struts form, even if I had quite
a hard time to figure out how to make it works but
I can't find any solution for 2 dimensions arrays.
the generated html corresponding parts are :
...
<td><input type="checkbox" name="enveloppes[0][7]" value="on"></td>
<td><input type="checkbox" name="enveloppes[1][7]" value="on"></td>
<td><input type="checkbox" name="enveloppes[0][8]" value="on"></td>
<td><input type="checkbox" name="enveloppes[1][8]" value="on"></td>
...
Thanks for the help,
Damien
---------------------------------------------------------------------
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