struts2 ModelDriven
问题说明,我为使程序层次清晰,我使用了ModelDriven
但在执行updateReceive.action和createReceive.action时,程序还未执行toEditReceive方法,怎么就返加 INPUT了。
如果把result返回的input去掉报错
Could not find action or result
No result defined for action com.toone.cost.basework.receive.action.ReceiveAction and result input - action
我没使用validation
跟踪,actionType值已set到form对象中去了。
请高手指教,初学struts2
//BASEAction对象
public class BaseAction extends ActionSupport implements ModelDriven {
public static final String CREATE = "create";
public static final String EDIT = "edit";
public static final String LIST = "list";
public static final String VIEW = "view";
// form对象
protected BaseForm form = new BaseForm();
}
//action对象
public class ReceiveAction extends BaseAction {
public static final String FRAME = "frame";
public static final String PRINT = "print";
private ReceiveService receiveService;
....以上只是action部分代码
/////spring 配置
<bean name="receiveForm"
class="com.toone.cost.basework.receive.action.ReceiveForm"
scope="prototype">
</bean>
<bean name="receiveAction"
class="com.toone.cost.basework.receive.action.ReceiveAction"
scope="prototype">
<property name="receiveService" ref="receiveService" />
<property name="form" ref="receiveForm" />
</bean>
////////////////////////////////////////////////////////
//action配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="baseWork" extends="struts-default">
<action name="receive" class="receiveAction" method="listReceive">
<result name="view">jsp/cost/basework/receive/receiveView.jsp</result>
<result name="frame">jsp/cost/basework/receive/receiveFrame.jsp</result>
<result name="list">jsp/cost/basework/receive/receiveList.jsp</result>
<result name="print">jsp/cost/basework/receive/receivePrint.jsp</result>
</action>
<action name="updateReceive" class="receiveAction" method="toEditReceive">
<param name="actionType">updateReceive</param>
<result name="edit">jsp/cost/basework/receive/receiveEdit.jsp</result>
</action>
<action name="createReceive" class="receiveAction" method="toEditReceive">
<param name="actionType">createReceive</param>
<result name="edit">jsp/cost/basework/receive/receiveEdit.jsp</result>
</action>
</package>
</struts>
=========================================================
------解决方案--------------------同意楼上!
------解决方案--------------------Struts2实现ModelDriven接口:
必须重写getModel方法
@Override
public Object getModel() {
return null;
}
你的Action中加入以下方法在尝试一下:
@Override
public ReceiveForm getModel() {
return receiveForm;
}
------解决方案--------------------<property name="receiveService" ref="receiveService"