日期:2014-05-17  浏览次数:20716 次

怎么在struts2中对Action内的Set对象赋值?
在struts中,做了一个iterator循环,里面对Set对象tms赋值,下面是我写的一个测试,仅列出主要代码,请高手帮我分析一下:
jsp
<s:form action="test" method="post">
<s:iterator value="new int[2]" status="st"> 

<s:textfield name="%{'tms.makeNew['+#st.index+'].testString'}" label="接口数值"/>
</s:iterator>
<s:submit></s:submit>
</s:form>
TestModel
public class TestModel {
private String testString;
private Integer testid;
setter & getter...
}

Action
public class testAction extends ActionSupport {
private Set<TestModel> tms = new LinkedHashSet<TestModel>();
public String execute(){

for(TestModel tm : tms){
System.out.println(tm.getTestString());
}
return SUCCESS;
}
}
struts.xml
<action name="test" class="test.testAction">
<result name="success">/logon.jsp</result>
</action>
运行后报错:
Error setting expression 'tms.makeNew[1].testString' with value '[Ljava.lang.String;@125b4d'
ognl.OgnlException: source is null for getProperty(null, "makeNew")

这个例子是从网上找到改动的,jsp中makeNew的方法没看到过,请问高手有什么办法吗?
struts2?iterator?Set

------解决方案--------------------
http://blog.csdn.net/withiter/article/details/5466977