【发布时间】:2012-11-12 05:17:12
【问题描述】:
我将 Strust2 用于表示层。我有带有下拉列表的 struts 表单,它与 java 对象(应用程序)列表绑定。 下拉显示应用程序对象列表,用户可以选择一个应用程序并提交。当在Action类中检索用户输入值时,接收值类型为“String”,我们不能直接从struts下拉中检索对象吗,以我为例“应用程序”对象
private List<Application> applicaionList = new ArrayList<Application>();
@Autowired
private ApplicationService applicationService;
private Application application;
public void loadTheForm(){
applicationList = applicationService.findAll();
}
public void submitForm(){
Document doc = new Document();
doc.setApplication(application);
}
//Getter Setters...
}
应用程序.jsp
<s:form action ="submitForm">
<s:select list ="applicationList" headerValue="---Select---" headerKey="-1" name="application"/>
</s:form>
struts.xml
<action name="submitForm" class="com.ActionSupport" method="submitForm">
<result name="success" type="tiles">/newAdminDocumentRequired.tiles</result>
</action>
当用户从下拉列表中选择值并提交时,提交的值为字符串, Struts中不能直接取对象吗,如果不能取到选中值的对象怎么办?
谢谢你, 乌德西卡
【问题讨论】:
-
你能重新表述一下这个问题吗?我无法理解你想要什么。
-
我现在改了,想知道用struts2不能直接获取对象吗?
-
好的,我已经添加了struts.xml的部分,这里我没有使用execute()方法
-
我可能很累,但我仍然没有抓住重点。请在一段中解释你想要什么。特别是当您说“...直接在 Struts 中获取对象...”时,“对象”是什么。猜测一下,您正在从下拉菜单中向操作发送一个值,那么您希望该值采用什么类型而不是字符串?
-
您有一个名为 com.ActionSupport 的用户定义类?
标签: struts2