JAVA struts2 继承modelDriven model
你可以看看struts2的源代码关于ModelDriven 拦截器的实现:
@Override
public String intercept(ActionInvocation invocation) throws Exception {
Object action = invocation.getAction();
if (action instanceof ModelDriven) {
ModelDriven modelDriven = (ModelDriven) action;
ValueStack stack = invocation.getStack();
Object model = modelDriven.getModel();
if (model != null) {
stack.push(model);
}
if (refreshModelBeforeResult) {
invocation.addPreResultListener(new RefreshModelBeforeResult(modelDriven, model));
}
}
return invocation.invoke();
}
如果你的action instanceof ModelDriven,struts会调用getModel();方法获得model然后stack.push(model);放进ValueStack中,不需要你手动push。
至于ValueStack如何实现将页面的data传入到Action中,可以参考下面的一篇博文:
http://lwx841017-yahoo-com-cn.iteye.com/blog/619815