我使用struts 2,我想使用struts标签。 我想用
<s:select list="types" name="list"/>从值堆栈中获取列表,这是我的操作代码
ValueStack valueStack = ServletActionContext.getContext().getValueStack(); valueStack.pop(); valueStack.push(types);但它没有用。这是错误信息
HTTP Status 500 - tag 'select', field 'list', name 'list': The requested list key '#types' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]但是,如果我将列表放入requestScope.It确实有效,就像这样<s:select list="types" name="#request.types"/>
所以我该怎么做?
I use struts 2 ,and I want to use struts tag. I want to use
<s:select list="types" name="list"/>to get a list from the value stack,Here is my action code
ValueStack valueStack = ServletActionContext.getContext().getValueStack(); valueStack.pop(); valueStack.push(types);But it didn't work.Here is the error message
HTTP Status 500 - tag 'select', field 'list', name 'list': The requested list key '#types' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]However if I put the list into the requestScope.It did work,like this<s:select list="types" name="#request.types"/>
So what should I do?
最满意答案
正如Walid所说,我应该在你的动作类中有一个getTypes()方法,而不是直接使用值栈。
所以我改变了我的代码:
List<String> types ; public List<String> getTypes() { return types; } types = dailyNewsService.getAllTypes();为了获得成功,请实现Preparable Interface并在其中加载“静态”数据:
@Override public void prepare() throws Exception { types = dailyNewsService.getAllTypes(); }As Walid said, i should have a getTypes() method in your action class instead of working directly with the value stack.
So I changed my code like this:
List<String> types ; public List<String> getTypes() { return types; } types = dailyNewsService.getAllTypes();For a succesful living, implement Preparable Interface and load there your "static" data:
@Override public void prepare() throws Exception { types = dailyNewsService.getAllTypes(); }无法从struts2中的值堆栈获取值(Can't get value from value stack in struts2)我使用struts 2,我想使用struts标签。 我想用
<s:select list="types" name="list"/>从值堆栈中获取列表,这是我的操作代码
ValueStack valueStack = ServletActionContext.getContext().getValueStack(); valueStack.pop(); valueStack.push(types);但它没有用。这是错误信息
HTTP Status 500 - tag 'select', field 'list', name 'list': The requested list key '#types' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]但是,如果我将列表放入requestScope.It确实有效,就像这样<s:select list="types" name="#request.types"/>
所以我该怎么做?
I use struts 2 ,and I want to use struts tag. I want to use
<s:select list="types" name="list"/>to get a list from the value stack,Here is my action code
ValueStack valueStack = ServletActionContext.getContext().getValueStack(); valueStack.pop(); valueStack.push(types);But it didn't work.Here is the error message
HTTP Status 500 - tag 'select', field 'list', name 'list': The requested list key '#types' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]However if I put the list into the requestScope.It did work,like this<s:select list="types" name="#request.types"/>
So what should I do?
最满意答案
正如Walid所说,我应该在你的动作类中有一个getTypes()方法,而不是直接使用值栈。
所以我改变了我的代码:
List<String> types ; public List<String> getTypes() { return types; } types = dailyNewsService.getAllTypes();为了获得成功,请实现Preparable Interface并在其中加载“静态”数据:
@Override public void prepare() throws Exception { types = dailyNewsService.getAllTypes(); }As Walid said, i should have a getTypes() method in your action class instead of working directly with the value stack.
So I changed my code like this:
List<String> types ; public List<String> getTypes() { return types; } types = dailyNewsService.getAllTypes();For a succesful living, implement Preparable Interface and load there your "static" data:
@Override public void prepare() throws Exception { types = dailyNewsService.getAllTypes(); }
发布评论