1 20 package org.enhydra.barracuda.contrib.dbroggisch.examples.view.pages; 21 22 import java.io.IOException ; 23 import java.util.List ; 24 import java.util.Locale ; 25 import javax.servlet.ServletException ; 26 import org.w3c.dom.Document ; 27 import org.enhydra.barracuda.core.comp.BAction; 29 import org.enhydra.barracuda.core.comp.BComponent; 30 import org.enhydra.barracuda.core.comp.BTemplate; 31 import org.enhydra.barracuda.core.comp.BText; 32 import org.enhydra.barracuda.core.comp.DefaultTemplateView; 33 import org.enhydra.barracuda.core.comp.ViewContext; 34 import org.enhydra.barracuda.core.event.EventException; 35 import org.enhydra.barracuda.core.util.dom.DefaultDOMLoader; 36 import org.enhydra.barracuda.contrib.dbroggisch.display.HashMapModel; 37 import org.enhydra.barracuda.contrib.dbroggisch.display.IterativeListModel; 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 PrefixmappingPage extends ExampleBasePage { 47 48 private static final Logger logger = Logger.getLogger(PrefixmappingPage.class.getName()); 49 50 List _maps; 51 52 public void setMaps(List maps) { 53 _maps = maps; 54 } 55 56 public void render(BComponent root, ViewContext vec, Document pDoc) 57 throws EventException, ServletException , IOException { 58 super.render(root, vec, pDoc); 59 Integer childCount = null; 60 PrefixMappingHTML doc = (PrefixMappingHTML) pDoc; 61 BTemplate mapComp = new BTemplate(); 62 63 mapComp.setView(new DefaultTemplateView(doc.getElementTestHook())); 64 65 if(_maps.size() > 0) { 66 RepopulationFormMap rfm = (RepopulationFormMap)_maps.remove(0); 68 mapComp.addModel(rfm); 69 childCount = (Integer )rfm.getVal(ParentFormMap.CHILD_COUNT); 70 } 71 72 IterativeListModel ilm = new IterativeListModel(ChildFormMap.MODEL_NAME, _maps) { 73 public Object getItem(String key) { 74 return ((RepopulationFormMap)_current).getItem(key); 75 } 76 }; 77 78 mapComp.addModel(ilm); 79 HashMapModel hmm = new HashMapModel(); 80 hmm.setName("ControlModel"); 81 hmm.setItem("SUBMIT", new BAction(new PrefixMapping())); 82 hmm.setItem("ADD", new BAction(new PrefixMappingAddChild())); 83 mapComp.addModel(hmm); 84 85 HashMapModel foo = new HashMapModel(); 86 foo.setName("FooModel"); 87 foo.setItem(ParentFormMap.CHILD_COUNT, new BText(childCount == null ? "None" : 88 childCount.intValue() == 0 ? "None" : 89 "" + childCount.intValue())); 90 91 mapComp.addModel(foo); 92 root.addChild(mapComp); 93 } 94 95 public Document getDocument(Locale iLocale) { 96 98 Document doc = null; 99 try {doc = DefaultDOMLoader.getGlobalInstance().getDOM(PrefixMappingHTML.class, iLocale);} 101 catch (IOException ioe) {logger.fatal ("Fatal Error loading DOM template:", ioe);} 102 return doc; 103 } 104 105 } 106 | Popular Tags |