随笔-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 阅读(296) 评论(0)  编辑  收藏 所属分类: WebWork

只有注册用户登录后才能发表评论。


网站导航: