Re: Re: Bug in BTable
Stefan Armbruster <[email protected]>
| Newsgroups | gmane.comp.java.enhydra.barracuda.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Tim,
regarding at the nested models stuff, take a look at
org.enhydra.barracuda.contrib.sam.models.IterativeSubModel.
Let me just point out how to use it. I'll assume your data is organized
in this way:
// item represents the content of one sub-element
class Item {
String name;
...
}
class Section {
String title;
<any other fields>
List items; // all items belonging to the Section
}
So each Section contains a List of Items. In your ControlEventHandler
(here I assume, you are using BTemplateViewHandler), you get a List of
Sections.
public Object getTemplateModels() {
List models = new Vector();
List sections = <call to your business logic>;
// create the "outer" model for sections
TemplateModel sectionModel = new IterativeListModel("Section",
sections) {
public Object getItem(String key) {
Section section = (Section)_current;
if ("title".equals(key)) {
return section.title;
} else {
... all other fields of section
} else if (key=="__REQ_FROM_CHILD") {
return section.items;
}
}
};
models.add(sectionModel);
// now the "inner" model iterating over the items
TemplateModel itemModel = new IterativeSubModel("Item",
"__REQ_FROM_CHILD", sectionModel) {
public Object getItem(Strin key) {
Item item = (Item)_current;
if ("name".equals(key)) {
return item.name;
} else ... <all other fields of Item>
}
};
models.add(itemModel);
}
So we have added two models, "Section" and "Item". The Item model has a
reference to section. For details how IterativeSubModel works, take a
look at the source.
Your HTML mockup would look like:
<h2 class="Dir::Iterate_Start.Section Dir::Iterate_Next.Section
Dir::Get_Data.Section.title">dummy for section's title</h2>
.... and outher Get_Data's on Section Model
<ul>
<li class="Dir::Iterate_Start.Item Dir::Iterate_Next.Item
Dir::Get_Data.Item.name">dummy for item's name
<li class="Dir::Iterate_End.Item Dir::Discard>null
</ul>
<h2 class="Dir::Iterate_End.Section Dir::Discard">null</h2>
Each section produces a h2 tag and a nested ul. The ul is populated by
the Item model.
I hope this helps.
Regards,
Stefan
Am Fre, 2003-07-18 um 22.05 schrieb Tim Dysinger:
> Greetings (again),
>
> How complex have you all pushed the component model? I noticed an email
> from Jim Dow a while back that asked about build custom components.
>
> I have a pretty complex couple of screens to build and so far I have not
> had any luck with build a custom component model for them.
>
> I would like to be able to build the following structure ->
>
> TemplateModel (page level model)
> -> BText (title)
> -> BList (links)
> -> BLink
> -> BList (repeating sections)
> -> BTemplate (section template)
> -> BText (section title)
> -> BList (list of stuff for the section)
> -> BText (stuff)
>
> -or-
>
> TemplateModel (page level model)
> -> BText (title)
> -> BList (links)
> -> BLink
> -> BTemplate (Iterative Model) (repeating sections)
> -> BText (section title)
> -> BTemplate (Iterative Model) (list of stuff for the section)
> -> BText (stuff)
>
> So far I have been able to manually bind any template model to a view and
> it works great, __but__ if I try to return any BTemplate from a
> TemplateModel it blows chunks. I have seen tidbits of emails on "Nested
> Directives." Can anyone point me to any examples/pointers? It seems that
> you cannot return a BTemplate from a TemplateModel.
>
> -Tim
>
>
>
> _______________________________________________
> Barracuda mailing list
> [email protected]
> http://barracudamvc.org/lists/listinfo/barracuda