wood burning stoves*
The moose likes Struts and the fly likes Checkbox in Iterator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Checkbox in Iterator" Watch "Checkbox in Iterator" New topic
Author

Checkbox in Iterator

Smita Ahuja
Greenhorn

Joined: Sep 23, 2013
Posts: 26
Hi,

My company is having one old application in struts 1.2 with java 1.4,
they want to make some changes in that application, they are looking for checkboxws in iteartor
I worked like below
formbean contains:
private String[] tenderChk;
jsp:
<logic:iterate name="tenderersList" id="tenderer">
<tr class="data">
<html:form action="SetupTenderersAction.do">
<html:hidden name="tenderer" property="tendererId"/>
<html:hidden property="mode" value="firstTimeEdit"/>
<html:hidden name="tenderFormBean" property="projectId"/>
<td>
<input type="checkbox" id="chk" name="tenderChk" value="<bean:write name="tenderer" property="tendererId" />"/>

I want tendererId value in array tenderChk;, so that I could work on its action, but I am not getting any value in my action class
TenderFormBean tenderFormBean = (TenderFormBean) form;
String checkbox[] = tenderFormBean.getTenderChk();
System.out.println("---checkbox--->>"+checkbox);

List list1 = Arrays.asList(checkbox);

System.out.println("----List1===>>>"+list1);

for(int i=0;i<checkbox.length;i++)
{
System.out.println("--for=="+checkbox[i]);
}
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8710
    
    6

You have to use indexed properties to do arrays of values.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Smita Ahuja
Greenhorn

Joined: Sep 23, 2013
Posts: 26
Hi Joe,

Could you please share any example for this..
Thanks
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8710
    
    6

So you didn't follow the link in my post that takes you to an excellent example? Googling for "Struts Indexed Properties" will get you others as well.
Smita Ahuja
Greenhorn

Joined: Sep 23, 2013
Posts: 26
Thanks Joe,

But my list is a Vector and I am getting it in jsp through request.setAttribute(in action)
How to set indexId in logic:iterate for the Vector List.

Vector tenderersList = tenderDelegate.loadTenderersList(tenderFormBean);

request.setAttribute("tenderFormBean", tenderFormBean);
request.setAttribute("tenderersList", tenderersList);
and Jsp:
<logic:iterate name="tenderersList" id="tenderer" >
<tr class="data">
<html:form action="SetupTenderersAction.do">
<html:hidden name="tenderer" property="tendererId"/>
<html:hidden property="mode" value="firstTimeEdit"/>
<html:hidden name="tenderFormBean" property="projectId"/>
<td>

<input type="checkbox" name="tenderChk" value="<bean:write name="tenderer" property="tendererId"/>"/>
</td>
and formbean is :

public class TendererFormBean extends ValidatorForm {
private String[] tenderChk;

public String[] getTenderChk() {
return tenderChk;
}


public void setTenderChk(String[] tenderChk) {
this.tenderChk = tenderChk;
}
}
 
jQuery in Action, 2nd edition
 
subject: Checkbox in Iterator
 
Similar Threads
form value is missing some times
IllegalArgumentException
Null pointer Exception when insert new record to database using struts2 and hibernate3
Displaytag pagination in Stripes
Arraylist in JSP with Html radio