I'm new to java and struts2, please help. from an action I have read and process a list created in a jsp
my problem is, how do I have access to data from an action of an iterator?
JSP PAGE
<s:iterator value="settoriList" var="myObj">
<tr>
<td>
<s:if test="#myObj.selected == 1">
<s:checkbox name="selected" fieldValue="%{cdSettore}" checked="checked"/>
<s:property value="cdSettore" />
</s:if>
<s:if test="#myObj.selected == 0">
<s:checkbox name="selected" value="false" fieldValue="%{cdSettore}" />
<s:property value="cdSettore" />
</s:if>
</td>
<td><s:property value="dsSettore" /></td>
<td><s:property value="dtIniVali" /></td>
<td><s:property value="dtFineVali" /></td>
</tr>
</s:iterator>
</table>
<s:hidden name="cdConve" />
<s:hidden name="process" value="saveSettori"/>
</s:form>
Here is how I am trying to access the data
private List<GenSettori> settoriList;
public List<GenSettori> getSettoriList() {
return settoriList;
}
public void setSettoriList(List<GenSettori> settoriList) {
this.settoriList = settoriList;
}
private String[] selected;
public String[] getSelected() {
return selected;
}
public void setSelected(String[] selected) {
this.selected = selected;
}
--------
settoriList = new ArrayList<GenSettori>();
System.out.println("list sett: "+settoriList);
for(int i=0;i<getSettoriList().size();i++){
if (getSelected()[i]!=""){
System.out.println("not selected "+getSelected()[i]);
}
}
---------
My page is formed by selected field, a description and a date.
Thanks in advance for any help
you can get string array from jsp to action class by following lines
In jsp
<s:hidden name="cdSettore" value="%{cdSettore}"></s:hidden>
If you want you can use
<s:if test="#myObj.selected == 0">
<s:hidden name="cdSettore" value="%{cdSettore}"></s:hidden>
</s:if>
to get not selected once
in action class
private String[] cdSettore;
public void setCdSettore(String[] cdSettore) {
this.cdSettore = cdSettore;
}
public String[] getCdSettore() {
return cdSettore;
}
for(int i=0;i<getCdSettore().length;i++){
System.out.println("not selected :"+getCdSettore()[i]);
}
Or you can do this
In jsp
<s:hidden name="cdSettore" value="%{cdSettore}"></s:hidden>
<s:if test="#myObj.selected == 1">
<s:checkbox name="selected" fieldValue="%{cdSettore}" checked="checked"/>
<s:property value="cdSettore" />
</s:if>
<s:if test="#myObj.selected == 0">
<s:checkbox name="selected" fieldValue="%{cdSettore}" />
<s:property value="cdSettore" />
</s:if>
In action class
for(int i=0;i<getCdSettore().length;i++){
int flag=0;
for(int j=0;j<getSelected().length;j++){
if(getCdSettore()[i].equalsIgnoreCase(getSelected()[j]))
{
flag++;
}
}
if(flag==0)
{
System.out.println("not selected :"+getCdSettore()[i]);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.