ModelDriven on struts 2

≯℡__Kan透↙ 提交于 2019-12-07 03:07:36

An approach with model driven action class is very useful if you are migrating old Struts code to a new one, so it simplifies a concept of form bean. And in the newer Struts 2 isn't necessary to use ModelDriven if you can use the action bean from the top of the value stack and model associated within just prefixed to its name.

Note, that when overriding interceptors configuration in the action config the defaultStack disappears. So, better to create your own stack or reference at least basicStack to make sure necessary interceptors are invoked. In your case a modelDriven interceptor.

If you use this interceptor on the stack it pushes the model in front of the action, so you don't need to s:push it in the result.

The model object should be initialized to the instance of he model class and returned by the getter of the model. Also consider using a visitor validator when validation fields of a model.

Having three actions that share a data between calls requires preparing a model using Preparable to populate fields from session or use a session object reference to provide default values for fields to keep them saved.

Note, using prepare requires changing the order of interceptors call to push the model before it's populated.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!