1 package org.enhydra.barracuda.tutorials.comp; 2 3 import java.io.*; 4 import java.util.*; 5 import javax.servlet.*; 6 import javax.servlet.http.*; 7 8 import org.w3c.dom.*; 9 import org.enhydra.xml.xmlc.*; 10 11 import org.enhydra.barracuda.core.comp.*; 12 import org.enhydra.barracuda.core.comp.helper.*; 13 import org.enhydra.barracuda.core.util.dom.*; 14 import org.enhydra.barracuda.tutorials.xmlc.*; 15 16 20 public class HelloWorld2a extends ComponentGateway { 21 22 25 29 public Document handleDefault (BComponent root, ViewContext vc, HttpServletRequest req, HttpServletResponse resp) throws IOException { 30 34 HelloWorld2aHTML page = (HelloWorld2aHTML)DefaultDOMLoader.getGlobalInstance().getDOM(HelloWorld2aHTML.class, vc.getViewCapabilities().getClientLocale()); 36 37 page.setTextTitle1("Hello World 2a example"); 40 page.setTextTitle2("Hello World 2a example"); 41 page.setTextDescr("This example illustrates how we can create populate a page using other Barracuda components--like BList--without putting anything in the HTML template except for standard XMLC style id values."); 42 43 String [] items = new String [] {"Cabbage", "Carrots", "Pickles", "Sugar", "Wheaties", "Flour", "Potatoes"}; 46 String [] qtys = new String [] {"3 heads", "1 bag", "1 jar", "5 lbs", "3 bxs", "50 lbs", "25 lbs"}; 47 ListModel listModel = new GroceriesModel(items, qtys); 48 View listView = new DefaultView(page.getElementShoppingList()); 49 BList wcList = new BList(listModel); 50 wcList.setView(listView); 51 root.addChild(wcList); 52 53 DefaultListModel flistModel = new DefaultListModel(); 55 View flistView = new DefaultView(page.getElementFooter()); 56 BList fwcList = new BList(flistModel); 57 fwcList.setView(flistView); 58 root.addChild(fwcList); 59 60 Node fn = HelloWorld2Footer.getNode(page.getDocument()); 63 NodeList nl = fn.getChildNodes(); 64 for (int i=0,max=nl.getLength(); i<max; i++) { 65 flistModel.add(nl.item(i)); 66 } 67 68 return page; 70 } 71 72 76 class GroceriesModel extends AbstractListModel { 77 78 String [] items = null; 79 String [] qtys = null; 80 81 public GroceriesModel(String [] iitems, String [] iqtys) { 83 items = iitems; 84 qtys = iqtys; 85 } 86 87 public Object getItemAt(int index) { 89 return qtys[index]+" "+items[index]; 90 } 91 92 public int getSize() { 94 return items.length; 95 } 96 } 97 98 } 99 | Popular Tags |