日期:2014-05-19  浏览次数:20651 次

OGNL内置List类型转换的问题。
在学习struts 2 in action这本书的时候遇到了一个问题。先上书本的例程代码
jsp内容:

<s:form action="ListDataTransferTest">

<s:textfield name="users[0].username" label="Usernames"></s:textfield>
<s:textfield name="users[1].username" label="Usernames"></s:textfield>
<s:textfield name="users[2].username" label="Usernames"></s:textfield>

<s:submit></s:submit>
</s:form>

java文件内容
private List users;

public List getUsers() {
return users;
}
public void setUsers(List users) {
this.users = users;
}
public String execute()
{
return SUCCESS;
}


然后在properties文件内为Action对象的List对象指定元素类型:

Element_users=com.hd.diasfloc.actionPackage.chapterFive.util.User

可以确定的配置好配置文件。但是结果:

严重: ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'users[0].username' on 'class com.hd.diasfloc.actionPackage.chapterFive.DataTransferTest: Error setting expression 'users[0].username' with value '[Ljava.lang.String;@1b43dd2'
2012-4-1 9:42:27 com.opensymphony.xwork2.interceptor.ParametersInterceptor setParameters
严重: ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'users[1].username' on 'class com.hd.diasfloc.actionPackage.chapterFive.DataTransferTest: Error setting expression 'users[1].username' with value '[Ljava.lang.String;@1c35be0'
2012-4-1 9:42:27 com.opensymphony.xwork2.interceptor.ParametersInterceptor setParameters
严重: ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'users[2].username' on 'class com.hd.diasfloc.actionPackage.chapterFive.DataTransferTest: Error setting expression 'users[2].username' with value '[Ljava.lang.String;@72e884'

照书上的说法是不需要预先初始化任何一个List,也不需要类型说明。而且也在properties文件里指定了List属性的类型。


然后在java代码里面的List改为List<User>就没有问题了,这是为啥呢?希望各位大侠指教

------解决方案--------------------
加载配置文件没...