1 package com.sun.facelets.tag.jstl.core; 2 3 import java.util.ArrayList ; 4 import java.util.Collection ; 5 import java.util.HashMap ; 6 import java.util.Map ; 7 8 import javax.faces.component.UIComponent; 9 import javax.faces.component.UIViewRoot; 10 import javax.faces.context.FacesContext; 11 12 import com.sun.facelets.Facelet; 13 import com.sun.facelets.FaceletFactory; 14 import com.sun.facelets.FaceletTestCase; 15 import com.sun.facelets.bean.Employee; 16 import com.sun.facelets.mock.MockResponseWriter; 17 import com.sun.facelets.util.FastWriter; 18 19 public final class JstlCoreTestCase extends FaceletTestCase { 20 21 public void testIf() throws Exception { 22 FacesContext faces = FacesContext.getCurrentInstance(); 23 Map session = faces.getExternalContext().getSessionMap(); 24 Employee e = new Employee(); 25 session.put("employee", e); 26 27 FaceletFactory f = FaceletFactory.getInstance(); 28 Facelet at = f.getFacelet("if.xml"); 29 30 UIViewRoot root = faces.getViewRoot(); 31 32 e.setManagement(true); 34 at.apply(faces, root); 35 UIComponent c = root.findComponent("form"); 36 assertNotNull("form is null", c); 37 38 e.setManagement(false); 40 at.apply(faces, root); 41 c = root.findComponent("form"); 42 assertNull("form is not null", c); 43 } 44 45 public void testForEach() throws Exception { 46 FacesContext faces = FacesContext.getCurrentInstance(); 47 Map session = faces.getExternalContext().getSessionMap(); 48 Collection c = new ArrayList (); 49 for (int i = 0; i < 10; i++) { 50 c.add(new Character ((char)('A' + i))); 51 } 52 session.put("list", c); 53 Map m = new HashMap (); 54 for (int i = 0; i < 10; i++) { 55 m.put("" + i, "" + i); 56 } 57 58 FaceletFactory f = FaceletFactory.getInstance(); 59 Facelet at = f.getFacelet("forEach.xml"); 60 61 UIViewRoot root = faces.getViewRoot(); 62 at.apply(faces, root); 63 64 FastWriter fw = new FastWriter(); 65 MockResponseWriter mrw = new MockResponseWriter(fw); 66 faces.setResponseWriter(mrw); 67 root.encodeAll(faces); 68 System.out.println(fw); 69 70 } 72 73 } 74 | Popular Tags |