Re: Need your suggestion on this,
Jacob Kjome <[email protected]>
| Newsgroups | gmane.comp.java.enhydra.barracuda.general |
|---|---|
| Message-ID | <[email protected]> |
Take a look at an example such as the HelloWorld2b example:
http://www.barracudamvc.org/Barracuda/src/org/enhydra/barracuda/tutorials/comp/HelloWorld2b.java
Look at the following code..
XMLObject page = xmlcFactory.create(pageCl);
//create the component and bind it to the view
BTemplate templateComp = new BTemplate();
templateComp.setView(new
DefaultTemplateView(page.getElementById("HelloWorld")));
//now specify the model
templateComp.addModel(new HelloWorldModel(pageNo));
String[] items = new String[] {"Cabbage", "Carrots", "Pickles", "Sugar",
"Wheaties", "Flour", "Potatoes", "Frozen Pepperoni Pizzas", "Pineapples",
"Honey-blanched Sardines", "Adobo", "Fresh Garlic cloves", "Milk",
"Chardonnay", "Spam", "Pickled Pigs Feet", "Antacid"};
String[] qtys = new String[] {"3 heads", "1 bag", "1 jar", "5 lbs", "3
bxs", "50 lbs", "25 lbs", "17", "3", "6 cans", "2 jars", "20", "5 gallons",
"3 bottles", "1 crate", "2 jars", "1 bottle"};
templateComp.addModel(new GroceriesModel(items, qtys));
//add the component to the root
root.addChild(templateComp);
So, a couple of separate models were added to the BTemplate component via
the addModel() method. If you look at the templates, you'll see the same
html file pointing to both models. For instance...
<p class="Dir::Get_Data.HelloWorld.Descr">[Descr]</p>
and
<span class="Dir::Get_Data.Groceries.Qty">3 cans</span>
So, a single template is gathering data from 2 separate models.
Does that help?
Jake
At 12:25 AM 4/11/2003 +0800, you wrote:
>Hi Jake,
>
>Thanks for your prompt response.
>
>Jacob Kjome wrote:
>
>>
>>Hi Damar,
>>
>>Hopefully I'm understanding the question. It seems to me that your
>>header and footer would be pretty much the same on the various pages,
>>right? So, then why deal with the header/footer stuff in every model?
>
>Yes, you are right.
>
>>You don't have to cram all your model logic into a single model. You can
>>have separate models for dealing with headers and footers and then have
>>more specific models that deal with the main contents of a page.
>>You might want to try compile-time SSI (server side includes) also to
>>simplify this process somewhat.
>>
>>Does that help? Have a model that deals with header and/or footer
>>information and have other models that deal with the main content of your
>>pages.
>
>As a novice, I still do not know the implementation detail. Can you please
>show me some code examples?
>
>Thanks.
>
>Damar
>
>>
>>Jake
>>
>>At 11:17 PM 4/10/2003 +0800, you wrote:
>>
>>>Hi,
>>>
>>>I have shown the snapshot of my MyPage.html, Header.html, and
>>>MyPageModel class of MyPage.java following this message. MyPage.java basically
>>>combines Header.html, Footer.html, and other html files into
>>>MyPage.html, and is working fine.
>>>To add a new page of similar kind, say Page1, I copied MyPage.java to
>>>Page1.java and MyPage.html to Page1.html. In Page1.java,class name
>>>changed to Page1(and other relevant changes),and in Page1.html, all
>>>"Dir::Get_Data.MyPage.???" became "Dir::Get_Data.Page1.???" (id became
>>>"Page1" etc).
>>>
>>>But,I have a problem with Header.html's "Dir::Get_Data.MyPage.Link1" (a
>>>BLink). To make it work for Page1, I have to
>>>change it to "Dir::Get_Data.Page1.Link1", I guess,which means I may have
>>>to have separate Header.html file for each new pages
>>>(not good approach, since Header.html is supposed to be for sharing).
>>>How can solve this problem,or am not to use Blink, but directly use <a
>>>href="somedomain.com/~link1" in Header.html file?
>>>
>>>Or can I do something in Page1.java within "if(key.equals("Link1")" to
>>>make it work?
>>>Any pointers would be highly appreciated.
>>>
>>>Damar
>>>
>>>
>>>======Start of MyPage.html======
>>>
>>>!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>>>[Header]
>>>[Footer]
>>>
>>>====Start of Header.html=====
>>>
>>>
>>>
>>><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>>>
>>>=====start of MyPage.java ============
>>>
>>>class MyPageModel extends AbstractTemplateModel {
>>>
>>> //register the model by name
>>> public String getName() {
>>> return "MyPage";
>>> }
>>>
>>> //provide items by key
>>> public Object getItem(String key) {
>>> ViewContext vc = getViewContext();
>>> if (key.equals("Title")) return "MyPage Title";
>>> else if (key.equals("Header")){
>>> XMLObject header =
>>>xmlcFactory.create(mypage.presentation.HeaderHTML.class);
>>> Node headerNode = header.getElementById("header");
>>> return
>>> vc.getElementFactory().getDocument().importNode(headerNode, true);
>>> }
>>>
>>> else if (key.equals("Footer")) {
>>> XMLObject footer =
>>>xmlcFactory.create(mypage.presentation.FooterHTML.class);
>>> Node footerNode = footer.getElementById("footer");
>>> return
>>> vc.getElementFactory().getDocument().importNode(footerNode, true);
>>> }
>>>
>>> else if(key.equals("Link1")){
>>> BLink blink1 = new
>>> BLink("","http://somedomain.com/~link1
>>> <http://somedomain.com/%7Elink1>", vc);
>>> return blink1;
>>> }
>>>
>>>
>>> else return super.getItem(key);
>>> }
>>> }
>>>}
>>>
>>>
>>>
>>>
>>>
>>>
>>>_______________________________________________
>>>Barracuda mailing list
>>>[email protected]
>>>http://barracudamvc.org/lists/listinfo/barracuda
>
>
>_______________________________________________
>Barracuda mailing list
>[email protected]
>http://barracudamvc.org/lists/listinfo/barracuda