打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
使用ModelDriven action
Model-Driven vs. Field-Driven
  two types of Actions possible:
  1. Model-driven
      Action has methods returning your model classes (myAction.getUser())
      Fields in the view are fields of your model
      Views refer directly to your model (property=‘user.name’)
      Excellent because it allows model reuse

  2. Field-driven
    Action has fields of its own, which are fields in the view
    execute() collates fields and interacts with the model
    Views refer to action fields (property=‘daysTillNextBirthday’)
    Useful where form is not parallel to model

 As we can see in our Action, the two can be mixed


ModelDriven Interface
XWork / WebWork also supports modeldriven Actions more directly
The ModelDriven Interface has one method:
        public Object getModel()
Properties of the model will be directly available, i.e. “name” instead of “user.name”
Applies to UI tags, form field names, etc.


步骤:
(1)Action implements ModelDriven接口
(2)实现getModel()方法:
    public Object getModel() {
        return user;
    }
(3)将jsp页面上user.name 改成name
(4)在xwork.xml中,
<pancakmaegsep ancaem=e"=/"eexx22""> extends="webwork-default"
  <action name="main" class="com.opensymphony.xwork.ActionSupport">
    <result>/model/form.jsp</result>
</action>

<action name="HelloWorld" class="example.ex2.HelloWorldAction">
    <interceptor-ref name="model-driven"/>
    <interceptor-ref name="defaultStack"/>
    <result>/model/success.jsp</result>
    <result name="input">/model/form.jsp</result>
</action>
</package>
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
ModelDriven使用
Struts2之ModelDriven的使用
模型驱动 ModelDriven
2.5.1 Action实现ModelDriven接口后的运行流程
【Struts2进阶】Struts2深度解析ModelDriven原理
Struts2教程
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服