[英]struts2 How read value iterator from jsp to action
I'm new to java and struts2, please help. 我是java和struts2的新手,请帮忙。 from an action I have read and process a list created in a jsp 从一个动作中,我已经阅读并处理了在jsp中创建的列表
my problem is, how do I have access to data from an action of an iterator? 我的问题是,如何从迭代器的操作访问数据?
JSP PAGE JSP页面
<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 您可以通过以下几行将字符串数组从jsp转换为动作类
In jsp 在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 在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]);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.