wood burning stoves*
The moose likes Struts and the fly likes How to create text boxes using array/collections using struts tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to create text boxes using array/collections using struts tag" Watch "How to create text boxes using array/collections using struts tag" New topic
Author

How to create text boxes using array/collections using struts tag

Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
Hi all,

I have 4 text boxes in a row and i have 10 such rows. I am using struts html tag and my code is as follows:

<tr>

<td>
1.
</td>
<td>
<html:text property="POD1"></html:text>
</td>
<td>
<html:text property="PONP1"></html:text>
</td>
<td>
<html:text property="POQ1" size="6"></html:text>
</td>
<td></td>
<td>
<html:text property="UOM1" size="4" value="nos."></html:text>
</td>
</tr>
<tr>
<td>
2.
</td>
<td>
<html:text property="POD2"></html:text>
</td>
<td>
<html:text property="PONP2"></html:text>
</td>
<td>
<html:text property="POQ2" size="6"></html:text>
</td>
<td></td>
<td>
<html:text property="UOM2" size="4" value="nos."></html:text>
</td>
</tr>

till 10.
I have corresponding getter setter methods in my Action Form.

My concern is , if in future i want to increase the number of text boxes, it would be very tedious for me to do so. Also the number of getters and setters will go on increasing.

So is there any other alternative to this? May be using array or collections?

Please help me out javascript:emoticon('');

Thanks

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Please, Post this topic in sturts forum. you may get better response

Coming to your question. you should read about Index Properties
Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
seetharaman venkatasamy wrote:Please, Post this topic in sturts forum. you may get better response

Coming to your question. you should read about Index Properties


Hi,

I had posted this question in struts forum, but one rancher told me to shift it to jsp forum. javascript:emoticon('');

Thanks for your prompt reply.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Deeps Mistry wrote:Thanks for your prompt reply.


You are welcome. and please read (and implement yourself) about the index property article. it is very usefull
Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
seetharaman venkatasamy wrote:
Deeps Mistry wrote:Thanks for your prompt reply.


You are welcome. and please read (and implement yourself) about the index property article. it is very usefull


Hi,

Is it compulsory to use DynaActionForm to implement the index property?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Deeps Mistry wrote:Is it compulsory to use DynaActionForm to implement the index property?


Not at All
Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
seetharaman venkatasamy wrote:
Deeps Mistry wrote:Is it compulsory to use DynaActionForm to implement the index property?


Not at All


Hi,

I am stuck and confused and dont know what to do further. Please help me out ranchers.

I tried using indexed property but didn't work out.

Please help me out.javascript:emoticon('');

Thanks
Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
Deeps Mistry wrote:
seetharaman venkatasamy wrote:
Deeps Mistry wrote:Is it compulsory to use DynaActionForm to implement the index property?


Not at All


Hi,

I am stuck and confused and dont know what to do further. Please help me out ranchers.

I tried using indexed property but didn't work out.

Please help me out.javascript:emoticon('');

Thanks


Hi all,

I tried the following:
1) Created a bean containing 4 getters setters for the 4 text boxes in a row.
2) Then i created an arraylist and added 10 new bean objects to it.
3) I set this arraylist in the form.
4) I put a logic iterate tag to iterate over the arraylist in my jsp page.

The code is a s follows:
My bean:

public class AddPOBean {

private String POD = null;
private String PON = null;
private String POQ = null;
private String UOM = null;


public String getPOD() {
return POD;
}
public void setPOD(String pod) {
POD = pod;
}
public String getPON() {
return PON;
}
public void setPON(String pon) {
PON = pon;
}
public String getPOQ() {
return POQ;
}
public void setPOQ(String poq) {
POQ = poq;
}
public String getUOM() {
return UOM;
}
public void setUOM(String uom) {
UOM = uom;
}

}

My Action class:

arrBean = new ArrayList();
for(int i = 0;i<10;i++)
{
objAddPOBean = new AddPOBean();
arrBean.add(objAddPOBean);
}
objAddPOForm.setArrBean(arrBean);

My jsp page:
<tr>
<td>
<logic:iterate id="AddPOForm" name="AddPOForm">
<html:text name ="AddPOForm" property="arrBean"></html:text>
</logic:iterate>
</td>
<tr>


I am getting the following error:

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot create iterator for this collection


Am i doing anything wrong? Please help me out

Thanks
Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
Deeps Mistry wrote:
Deeps Mistry wrote:
seetharaman venkatasamy wrote:
Deeps Mistry wrote:Is it compulsory to use DynaActionForm to implement the index property?


Not at All


Hi,

I am stuck and confused and dont know what to do further. Please help me out ranchers.

I tried using indexed property but didn't work out.

Please help me out.javascript:emoticon('');

Thanks


Hi all,

I tried the following:
1) Created a bean containing 4 getters setters for the 4 text boxes in a row.
2) Then i created an arraylist and added 10 new bean objects to it.
3) I set this arraylist in the form.
4) I put a logic iterate tag to iterate over the arraylist in my jsp page.

The code is a s follows:
My bean:

public class AddPOBean {

private String POD = null;
private String PON = null;
private String POQ = null;
private String UOM = null;


public String getPOD() {
return POD;
}
public void setPOD(String pod) {
POD = pod;
}
public String getPON() {
return PON;
}
public void setPON(String pon) {
PON = pon;
}
public String getPOQ() {
return POQ;
}
public void setPOQ(String poq) {
POQ = poq;
}
public String getUOM() {
return UOM;
}
public void setUOM(String uom) {
UOM = uom;
}

}

My Action class:

arrBean = new ArrayList();
for(int i = 0;i<10;i++)
{
objAddPOBean = new AddPOBean();
arrBean.add(objAddPOBean);
}
objAddPOForm.setArrBean(arrBean);

My jsp page:
<tr>
<td>
<logic:iterate id="AddPOForm" name="AddPOForm">
<html:text name ="AddPOForm" property="arrBean"></html:text>
</logic:iterate>
</td>
<tr>


I am getting the following error:

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot create iterator for this collection


Am i doing anything wrong? Please help me out

Thanks


Hey Ranchers...please help me out
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to create text boxes using array/collections using struts tag