隨筆-348  評論-598  文章-0  trackbacks-0
          //Example 1: This is wrong:
          public class ViewHeadlineAction implements Action, ModelDriven {
          Headline headline 
          = new Headline();
          public Object getModel() {
          return this.headline ;
          }

          // 
          public String execute() {
          headline 
          = headlineFactory.findLatest();
          return SUCCESS;
          }

          }

          b
          //Example 2: This is correct:
          public class ViewHeadlineAction implements Action, ModelDriven {
          Headline headline 
          = new Headline();
          public Object getModel() {
          return this.headline ;
          }

          // 
          public String execute() {
          headlineFactory.updateToLatest(headline);
          return SUCCESS;
          }

          }

          Example 1 attempts to change the instance that getModel() returns. However,
          because getModel() is called before execute() and before the object is pushed
          onto the value stack, the reference that WebWork uses is the original instance, created
          by new Headline(), not the instance loaded from the HeadlineFactory. The
          second example resolves this issue by updating the existing instance rather than
          having headline point to a new instance.

          ---------------------------------------------------------
          專注移動開發(fā)

          Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
          posted on 2007-04-11 18:30 TiGERTiAN 閱讀(313) 評論(0)  編輯  收藏 所屬分類: WebWork
          主站蜘蛛池模板: 蒙阴县| 中西区| 扬州市| 偃师市| 和政县| 堆龙德庆县| 探索| 雷州市| 南乐县| 南皮县| 饶平县| 定安县| 关岭| 临湘市| 南乐县| 民权县| 文安县| 桓仁| 介休市| 金阳县| 灌南县| 思南县| 盐亭县| 名山县| 德庆县| 德州市| 饶阳县| 乐东| 景泰县| 庄浪县| 中山市| 临汾市| 南郑县| 小金县| 邮箱| 微博| 武宁县| 泽普县| 资源县| 巧家县| 通渭县|