隨筆-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.

          ---------------------------------------------------------
          專注移動開發

          Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
          posted on 2007-04-11 18:30 TiGERTiAN 閱讀(313) 評論(0)  編輯  收藏 所屬分類: WebWork
          主站蜘蛛池模板: 绥宁县| 大名县| 博乐市| 丘北县| 来凤县| 乐业县| 蒲江县| 诸暨市| 镇雄县| 广昌县| 华池县| 池州市| 盐源县| 张家川| 永州市| 晋宁县| 华亭县| 甘洛县| 庄河市| 襄城县| 丹棱县| 余江县| 淮滨县| 仙居县| 赣榆县| 河南省| 唐山市| 志丹县| 孝昌县| 太原市| 咸阳市| 六枝特区| 滁州市| 调兵山市| 延津县| 中宁县| 濮阳县| 博罗县| 麟游县| 黔西| 虎林市|