Fwd: Re: Iterative Model
"Diez B. Roggisch" <[email protected]>
| Newsgroups | gmane.comp.java.enhydra.barracuda.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Suroor, this is something from the list a while ago. Does this give you an idea? Basically, the recursion of your example is replaced by - setting the child collection to the child model when a new top-level object is visited in iterate-next - instead of diving into it recursively, the markup directives are beeing called on the child model and then the childs are traversed. Of course this stuff can be nested as deep as you want - but unfortunately only with pre-known depth. Jacob mentions two things: 1) A FAQ entry about this. I'd be willing to contribute if we had setup a wiki or something alike - it seems to me that this is the way to go these days. 2) automatic parent-child-models. Well - this _could_ be done, but only if the tree objects implement a certain Node-style interface - which is often not desirable. Hope this helps, Diez ---------- Weitergeleitete Nachricht ---------- Subject: Re: [Barracuda] Iterative Model Date: Samstag, 15. März 2003 18:07 From: Jacob Kjome <[email protected]> To: [email protected] As a follow-up to what Diez says, here is something Diez actually sent me quite a while ago that I think might help... ParentModel extends AbstractTemplateModel implements IterativeModel { ParentItem current; ParentItem getCurrent() {return current;} /* ... all the model-stuff */ public void loadNext() { current = calcMyNextCurrentItem(); } } ChildModel extends AbstractTemplateModel implements IterativeModel { public ChildModel(ParentModel); // Save the ref to ParentModel public void preIterate() { ParentItem pi = parentModel.getCurrent(); childs = pi.getMyChildsAsList(); } } Hope that helps. This really does need to be in a FAQ of some sort. Anyone want to start work on that? It would also be nice to have a more automatic way for child models to interact with parent models more automatically. I'm not saying I have something in mind. It just seems this could be done in a more elegant way. Jake
(text/html, 2.9 KB)
<html>
<body>
<font size=3><br>
As a follow-up to what Diez says, here is something Diez actually sent me
quite a while ago that I think might help...<br><br>
</font><font face="arial" size=2 color="#0000FF">ParentModel extends
AbstractTemplateModel implements IterativeModel {<br>
</font><font size=3> <br>
</font><font face="arial" size=2 color="#0000FF">
ParentItem current;<br>
</font><font size=3> <br>
</font><font face="arial" size=2 color="#0000FF">
ParentItem getCurrent() {return current;}<br>
</font><font size=3> <br>
</font><font face="arial" size=2 color="#0000FF"> /*
... all the model-stuff */<br>
</font><font size=3> <br>
</font><font face="arial" size=2 color="#0000FF">
<br>
public void <b>loadNext</b>() {<br>
current =
calcMyNextCurrentItem();<br>
}<br>
<br>
}<br>
</font><font size=3> <br>
</font><font face="arial" size=2 color="#0000FF">ChildModel extends
AbstractTemplateModel implements IterativeModel {<br>
</font><font size=3> <br>
</font><font face="arial" size=2 color="#0000FF">
public ChildModel(ParentModel); // Save the ref to ParentModel<br>
</font><font size=3> <br>
<br>
<br>
</font><font face="arial" size=2 color="#0000FF">
public void <b>preIterate</b>() {<br>
ParentItem pi =
parentModel.getCurrent();<br>
childs =
pi.getMyChildsAsList();<br>
}<br>
<br>
}<br>
</font><font size=3> <br><br>
Hope that helps.<br><br>
This really does need to be in a FAQ of some sort. Anyone want to
start work on that? It would also be nice to have a more automatic
way for child models to interact with parent models more
automatically. I'm not saying I have something in mind. It
just seems this could be done in a more elegant way.<br><br>
<br>
Jake<br><br>
At 01:39 PM 3/15/2003 +0100, you wrote:<br>
<blockquote type=cite class=cite cite>Hi,<br><br>
> I am trying to figure out how to use the current Iterative Model to
do<br>
> this. Has anyone come across similar problem ? Any insight regarding
this<br>
> would be really helpful.<br><br>
Search the mail archives for parent and child iteratice models. The basic
idea <br>
is to have two models, where the outer one initializes the inner one when
<br>
iterateNext is called - or the inner one queries the outter one about its
<br>
parent object in the preIterate method.<br><br>
Diez<br>
_______________________________________________<br>
Barracuda mailing list<br>
[email protected]<br>
<a href="http://barracudamvc.org/lists/listinfo/barracuda" eudora="autourl">http://barracudamvc.org/lists/listinfo/barracuda</a></font></blockquote></body>
</html>