The sequence of ModelDriven and Prepare?

隐身守侯 提交于 2019-12-08 06:29:29

You have to set the Model object yourself as the modeldriven interceptor can only push it to the stack if its not null. If your getModel() looks like this:

SomeModelClass myModelObject = null;

public Object getModel()
{
   return myModelObject;
}

... you'll have to set the modelObject so it can get pushed to the valueStack. You could do it this way I guess:

public void prepare(){
   myModelObject = new myModelObject("I'm so new");
}

... or just initialize it in the field:

SomeModelClass myModelObject = new myModelObject("I'm so new");

Don't forget to implement the appropriate Interfaces (ModelDriven and Preparable). Hope this helps a bit.

I found my own solution.. but not a good one..

When setting domain object by setter, I push it to the valuestack manually..

It works good and only 2 lines added to my class.

But I don't feel that good.

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