1 package com.sun.facelets.tag.jsf.html; 2 3 import javax.el.MethodExpression; 4 import javax.faces.component.ActionSource2; 5 import javax.faces.component.UIComponent; 6 import javax.faces.component.UIViewRoot; 7 import javax.faces.context.FacesContext; 8 9 import com.sun.facelets.Facelet; 10 import com.sun.facelets.FaceletFactory; 11 import com.sun.facelets.FaceletTestCase; 12 13 public class HtmlTestCase extends FaceletTestCase { 14 15 public void testCommandComponent() throws Exception { 16 FacesContext faces = FacesContext.getCurrentInstance(); 17 this.servletRequest.getSession().setAttribute("test", new TestBean()); 18 19 FaceletFactory f = FaceletFactory.getInstance(); 20 Facelet at = f.getFacelet("componentOwner.xml"); 21 22 UIViewRoot root = faces.getViewRoot(); 23 at.apply(faces, root); 24 25 UIComponent c = root.findComponent("cmd"); 26 assertNotNull("cmd", c); 27 28 Object v = c.getAttributes().get("id"); 29 assertEquals("id", "cmd", v); 30 31 ActionSource2 as2 = (ActionSource2) c; 32 MethodExpression me = as2.getActionExpression(); 33 assertNotNull("method", me); 34 35 String result = (String ) me.invoke(faces.getELContext(), null); 36 System.out.println(result); 37 } 38 39 public void testCommandButton() throws Exception { 40 FacesContext faces = FacesContext.getCurrentInstance(); 41 42 FaceletFactory f = FaceletFactory.getInstance(); 43 Facelet at = f.getFacelet("commandButton.xml"); 44 45 UIViewRoot root = faces.getViewRoot(); 46 at.apply(faces, root); 47 48 UIComponent c = root.findComponent("form:button"); 49 assertNotNull("button", c); 50 51 Object v = c.getAttributes().get("id"); 52 assertEquals("id", "button", v); 53 } 54 55 public void testPanelGrid() throws Exception { 56 FacesContext faces = FacesContext.getCurrentInstance(); 57 58 FaceletFactory f = FaceletFactory.getInstance(); 59 Facelet at = f.getFacelet("panelGrid.xml"); 60 61 UIViewRoot root = faces.getViewRoot(); 62 at.apply(faces, root); 63 } 64 65 } 66 | Popular Tags |