我使用Strust2作爲表示層。我使用下拉的struts形式與java對象(應用程序)列表綁定。 下拉列表顯示應用程序對象列表,用戶可以選擇一個應用程序並提交。當在Action類中檢索用戶輸入值時,接收值類型是「String」,我們不能直接從struts下拉對象中檢索對象,在我的情況下 「應用程序」 對象使用Struts的Java對象下拉
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...
}
application.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中使用該對象嗎?
謝謝 Udeshika
你能改述這個問題嗎?我無法理解你想要什麼。 – Quaternion
我現在改變了它,我想知道我們不能使用struts2獲得直接對象嗎? – ExCode
好的,我已經添加了struts的一部分。xml,我沒有在這裏使用execute()方法 – ExCode