1 package org.enhydra.barracuda.examples.xmlc; 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.w3c.dom.html.*; 10 import org.enhydra.xml.xmlc.*; 11 12 import org.enhydra.barracuda.core.comp.*; 13 import org.enhydra.barracuda.core.comp.helper.*; 14 import org.enhydra.barracuda.core.util.dom.*; 15 import org.enhydra.barracuda.core.event.*; 16 import org.enhydra.barracuda.core.view.*; 17 import org.enhydra.barracuda.examples.xmlc.data.*; 18 19 23 public class CompEx4 extends ComponentGateway { 24 25 private ListenerFactory getLinkFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new GetLinkHandler();} public String getListenerID() {return getID(GetLinkHandler.class);}}; 26 27 31 public Document handleDefault (BComponent root, ViewContext vc, HttpServletRequest req, HttpServletResponse resp) throws IOException { 32 Document page = DefaultDOMLoader.getGlobalInstance().getDOM(CompEx4HTML.class); 34 35 BTemplate templateComp = new BTemplate(new SimpleModel()); 37 templateComp.setView(new DefaultTemplateView(page.getElementById("TemplateID"))); 38 root.addChild(templateComp); 39 40 return page; 42 } 43 44 50 public DOMWriter getDOMWriter() { 51 return new DefaultDOMWriter(true); 53 } 54 55 59 class SimpleModel extends AbstractTemplateModel { 60 public String getName() { 62 return "SimpleModel"; 63 } 64 65 public Object getItem(TemplateDirective td) { 67 ViewContext vc = getViewContext(); 68 String key = td.getKeyName(); 69 if (key.equals("Link1")) { 70 BAction baction = new BAction(); 71 baction.addEventListener(getLinkFactory); 73 baction.setParam("foo1","blah1"); 74 baction.setParam("foo2","blah2"); 75 return baction; 76 } else if (key.equals("Link2")) { 77 BAction baction = new BAction("http://blah.com/testLink2.html"); 78 return baction; 79 } else if (key.equals("Link3")) { 80 BLink blink = new BLink("link example (event)"); 81 blink.addEventListener(getLinkFactory); 82 blink.setParam("foo1","blah1"); 83 blink.setParam("foo2","blah2"); 84 return blink; 85 } else if (key.equals("Link4")) { 86 BLink blink = new BLink("link example (url)", "http://blah.com/testBLink.html"); 87 return blink; 88 } else if (key.equals("Link5")) { 89 BAction baction = new BAction("http://blah.com/testLink2.html"); 90 baction.setEnabled(false); 91 return baction; 92 } else if (key.equals("Form1")) { 93 BAction baction = new BAction("http://blah.com/formTest1.html"); 94 return baction; 95 } else if (key.equals("Button1")) { 96 BAction baction = new BAction(); 97 baction.addEventListener(getLinkFactory); 98 return baction; 99 } else if (key.equals("Button2")) { 100 BLink blink = new BLink("link example on a button", "http://blah.com/testBLink.html"); 101 return blink; 102 } else return super.getItem(key); 103 } 104 } 105 106 110 class GetLinkHandler extends DefaultBaseEventListener { 111 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 112 113 } 115 } 116 117 118 } 119 | Popular Tags |