Hi Martin,

I saw the same type of behavior you are talking about with LoadableDetachableModels not detaching but AbstractReadOnlyModel's working properly.

What I found was that I was instantiating my LDM's as private variables in my custom components but that they were not being detached. In this case you need to programatically register your non default models to participate in the detachment process. See the Wiki here for an example:

http://cwiki.apache.org/confluence/display/WICKET/Working+with+Wicket+models#WorkingwithWicketmodels-ManagingthelifecycleofnondefaultdetachableIModel%27s

For your option 3 I would say you should create a custom IModel implementation that is aware of your caching strategy so that your Component's don't need to care about how the data is loaded.

Your implementation could hold a Map of all related models and update according to your rules or better yet build a service that does the caching and dirty detection and then just have the LDM source the cell value from the service. Something like:

new LoabableDetachableModel () {

    protected CellValue load () {

           return cellService.getValue (row, col);
  }
}

Regards,

Mike

evaluated only one time per render can be done with
LoadableDetachedModel ..

I do not mean LOADED once per render. I mean EVALUATED once per
render. In my understanding LoadableDetachableModel does not guarantee
"reset" in any particular stage.

can you explain it a littly bit (a link to your original message?)

I mean for rexample I have many models like this:

new AbstractReadOnlyModel<String>() {
   public String getObject() {
      // evaluate message with some logic
      return message;
   }
}

Furthermore, I have several components that, say, depend on this
value. This getObject() will be called many times durung render and
the logic will be evaluated many times.

If I make it detachable it will yes be detached but I am not sure that
the detaching is guaranteed at some specific point in request cycle?

To make my "use case" more clear I will give an example: say I have a
wicket page with a panel that contains a table with columns rows and y
rows. Furthermore, let's assume it is a spreadsheet emulator: you can
write formulas into the cells that depend on the other cells which
means that the value of each cell is recursively evaluated dependent
on the other cell's values.

Requirements:
1. During render time each cell's model value should be cached once it
has been evaluated (we do not want to recurse many times to fetch the
same value).
2. If the value of any cell changes, all the dependent cells should be
(for example) ajax refreshed and re-evaluated. For simplicity, we
could re-set the cache of all models when change occurs. And
redraw-all.
3. We want to reset cache ONLY if change occurs.

In my understanding requirement 3 cannot be directly reached with
detachable models.

**
Martin


Reply via email to