一般來說,我已經看到它在Struts中完成的方式是通過Form對象。這個表單類擴展了ActionForm。然後在struts-config.xml中將這個表單定義爲一個表單bean。然後在動作類bean定義中添加對錶單bean的引用。然後在jsp中修改表單以從DTO獲取數據。
例如: -
The Action class:
public class SomeAction extends DispatchAction {
public ActionForward someRequest(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)
throws Exception {
SomeForm someForm = (SomeForm) form;
List<SomeDTO> someList = populateDto();
someForm.setSomeList(someList);
return mapping.findForward("someAction");
}
The Form class:
public class SomeForm extends ActionForm{
List<SomeDTO> someList;
//getter and setters for someList
}
StrutsConfig:
<form-beans>
<form-bean name="someForm" type="my.forms.SomeForm" />
</form-beans>
<action path="/someRequest"
type="my.actions.SomeAction"
name="someForm" scope="request" >
<forward name="someAction" path="goesSomeWhere" />
</action>
View:
<c:forEach items="${someForm.someList}" var="someThing" varStatus="someCounter">
<c:out value="${someThing.foo}" /> <!-- assuming foo is a member in SomeThing DTO -->
</c:forEach>
這將是有意義的,但名字的ActionForm是有點混亂,如果它使用這種方式。它看起來像一個解決方法:-)但它沒有關係,如果它服務良好,謝謝 – lisak 2010-11-05 20:33:20
不客氣。 :-) – CoolBeans 2010-11-05 21:01:12