KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > contrib > dbroggisch > examples > view > pages > RepopulationPage


1 /*
2  * Copyright (C) 2003 Diez B. Roggisch [deets@web.de]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: RepopulationPage.java,v 1.2 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.contrib.dbroggisch.examples.view.pages;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Locale JavaDoc;
26 import javax.servlet.ServletException JavaDoc;
27 import org.w3c.dom.Document JavaDoc;
28 //import org.enhydra.xml.xmlc.XMLCStdFactory;
29
import org.enhydra.barracuda.core.comp.BAction;
30 import org.enhydra.barracuda.core.comp.BComponent;
31 import org.enhydra.barracuda.core.comp.BTemplate;
32 import org.enhydra.barracuda.core.comp.DefaultTemplateView;
33 import org.enhydra.barracuda.core.comp.TemplateModel;
34 import org.enhydra.barracuda.core.comp.ViewContext;
35 import org.enhydra.barracuda.core.event.EventException;
36 import org.enhydra.barracuda.core.util.dom.DefaultDOMLoader;
37 import org.enhydra.barracuda.contrib.dbroggisch.display.HashMapModel;
38 import org.enhydra.barracuda.contrib.dbroggisch.repopulation.RepopulationFormMap;
39 import org.apache.log4j.Logger;
40
41 import org.enhydra.barracuda.contrib.dbroggisch.examples.controller.events.*;
42 import org.enhydra.barracuda.contrib.dbroggisch.examples.model.forms.*;
43 import org.enhydra.barracuda.contrib.dbroggisch.examples.view.xmlc.*;
44
45
46 public class RepopulationPage extends ExampleBasePage {
47
48     private static final Logger logger = Logger.getLogger(RepopulationPage.class.getName());
49
50     RepopulationFormMap _rfm;
51
52     public void setRFM(RepopulationFormMap rfm) {
53         _rfm = rfm;
54     }
55
56     public void render(BComponent root, ViewContext vec, Document JavaDoc pDoc)
57             throws EventException, ServletException JavaDoc, IOException JavaDoc {
58         super.render(root, vec, pDoc);
59         RepopulationHTML doc = (RepopulationHTML) pDoc;
60
61         // Fetch the map that's supposed to act as template model.
62
ExampleFormMap cfm = (ExampleFormMap)_rfm;
63         BTemplate loginComp = new BTemplate();
64
65         loginComp.setView(new DefaultTemplateView(doc.getElementTestHook()));
66
67         // Add the map as model to the BTemplate
68
loginComp.addModel(cfm);
69
70         // It is possible that the map contains multiple choice elements represented by their respective model.
71
// That happens when you use CheckBoxes or Radiobuttons instead of combo-boxes.
72
// For now, Barracuda lacks the possibility to add these automatically, so we have to do it.
73
List JavaDoc cModels = cfm.getChildModels();
74         for(Iterator JavaDoc it = cModels.iterator(); it.hasNext();) {
75             loginComp.addModel((TemplateModel)it.next());
76         }
77
78         // A simple hashmap based model for the buttons.
79
HashMapModel hmm = new HashMapModel();
80         hmm.setName("ControlModel");
81         hmm.setItem("SUBMIT", new BAction(new Repopulation()));
82         loginComp.addModel(hmm);
83         root.addChild(loginComp);
84     }
85
86     public Document JavaDoc getDocument(Locale JavaDoc iLocale) {
87         //return new XMLCStdFactory(null, null).create(RepopulationHTML.class);
88

89         Document JavaDoc doc = null;
90         //load the localized DOM template
91
try {doc = DefaultDOMLoader.getGlobalInstance().getDOM(RepopulationHTML.class, iLocale);}
92         catch (IOException JavaDoc ioe) {logger.fatal ("Fatal Error loading DOM template:", ioe);}
93         return doc;
94     }
95
96 }
97
Popular Tags