1 14 15 package com.sun.facelets.tag.jsf.core; 16 17 import java.io.IOException ; 18 import java.util.logging.Logger ; 19 20 import javax.el.ELException; 21 import javax.el.MethodExpression; 22 import javax.faces.FacesException; 23 import javax.faces.component.UIComponent; 24 import javax.faces.component.UIViewRoot; 25 import javax.faces.event.PhaseEvent; 26 27 import com.sun.facelets.FaceletContext; 28 import com.sun.facelets.FaceletException; 29 import com.sun.facelets.tag.TagAttribute; 30 import com.sun.facelets.tag.TagConfig; 31 import com.sun.facelets.tag.TagHandler; 32 import com.sun.facelets.tag.jsf.ComponentSupport; 33 34 43 public final class ViewHandler extends TagHandler { 44 45 private final static Class [] LISTENER_SIG = new Class [] { PhaseEvent.class }; 46 47 private final TagAttribute locale; 48 49 private final TagAttribute renderKitId; 50 51 private final TagAttribute contentType; 52 53 private final TagAttribute encoding; 54 55 private final TagAttribute beforePhaseListener; 56 57 private final TagAttribute afterPhaseListener; 58 59 62 public ViewHandler(TagConfig config) { 63 super(config); 64 this.locale = this.getAttribute("locale"); 65 this.renderKitId = this.getAttribute("renderKitId"); 66 this.contentType = this.getAttribute("contentType"); 67 this.encoding = this.getAttribute("encoding"); 68 this.beforePhaseListener = this.getAttribute("beforePhaseListener"); 69 this.afterPhaseListener = this.getAttribute("afterPhaseListener"); 70 } 71 72 78 public void apply(FaceletContext ctx, UIComponent parent) 79 throws IOException , FacesException, FaceletException, ELException { 80 UIViewRoot root = ComponentSupport.getViewRoot(ctx, parent); 81 if (root != null) { 82 if (this.locale != null) { 83 root.setLocale(ComponentSupport.getLocale(ctx, 84 this.locale)); 85 } 86 if (this.renderKitId != null) { 87 String v = this.renderKitId.getValue(ctx); 88 root.setRenderKitId(v); 89 } 90 if (this.contentType != null) { 91 String v = this.contentType.getValue(ctx); 92 ctx.getFacesContext().getExternalContext().getRequestMap().put("facelets.ContentType", v); 93 } 94 if (this.encoding != null) { 95 String v = this.encoding.getValue(ctx); 96 ctx.getFacesContext().getExternalContext().getRequestMap().put("facelets.Encoding", v); 97 } 98 if (this.beforePhaseListener != null) { 99 MethodExpression m = this.beforePhaseListener 100 .getMethodExpression(ctx, null, LISTENER_SIG); 101 root.setBeforePhaseListener(m); 102 } 103 if (this.afterPhaseListener != null) { 104 MethodExpression m = this.afterPhaseListener 105 .getMethodExpression(ctx, null, LISTENER_SIG); 106 root.setAfterPhaseListener(m); 107 } 108 } 109 this.nextHandler.apply(ctx, parent); 110 } 111 112 } 113 | Popular Tags |