Struts does not support filling a multidimensional array in a Form bean. However, it processes a one-dimensional array of the object. Therefore, if you can create a class (say, MatrixRow) that itself contains an Uni-dimensional array, then you can create a Uni-dimensional array of this object in the form of a bean. Your new class will look like
public class MatrixRow { private String matrixCol[] = new String[10]; public String[] getMatrixCol() { return matrixCol; } public void setMatrixCol(String[] matrixCol) { this.matrixCol = matrixCol; } }
Then in your bean form
private MatrixRow[] arrMatrix = new MatrixRow[10]; public MatrixRow[] getArrMatrix() { return arrMatrix; } public void setArrMatrix(MatrixRow[] arrMatrix) { this.arrMatrix = arrMatrix; }
and in your JSP you can use it somehow like
<html:form action="biArrayTestAction.do"> <table cellpadding="0" cellspacing="0" width="100%"> <logic:iterate id="matrixRows" name="biArrayTestForm" property="arrMatrix" indexId="sno" type="logic.MatrixRow" > <tr> <td><bean:write name="sno"/></td> <logic:iterate id="matrixCol" name="matrixRows" property="matrixCol" indexId = "colNo"> <td> <input type="text" name="arrMatrix[<%=sno %>].matrixCol[<%=colNo %>]"> </td> </logic:iterate> </tr> </logic:iterate> <tr> <td align="center" valign="top" colspan="2"> </td> </tr> <tr> <td align="center" valign="top" colspan="2"> <html:submit property="command" value="Test"></html:submit> </td> </tr> </table>
When you submit this form, you will receive all the columns of the MatrixRow object filled with values.
Hope this helps you. I have not found another way to use a multidimensional array in Struts1.
source share