thanks a lot Atta, it is working fine.

-----Message d'origine-----
De : atta-ur rehman [mailto:[EMAIL PROTECTED]
Envoyé : vendredi 9 juillet 2004 20:09
À : Struts Users Mailing List
Objet : Re: Form with n columns and m raws


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" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
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: [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]

Reply via email to