Source code: com/sun/facelets/tag/jsf/core/ViewHandler.java
1 /**
2 * Licensed under the Common Development and Distribution License,
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.sun.com/cddl/
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11 * implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
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 /**
35 * Container for all JavaServer Faces core and custom component actions used on
36 * a page. <p/> See <a target="_new"
37 * href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/tlddocs/f/view.html">tag
38 * documentation</a>.
39 *
40 * @author Jacob Hookom
41 * @version $Id: ViewHandler.java,v 1.4 2006/05/09 06:25:41 jhook Exp $
42 */
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 /**
60 * @param config
61 */
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 /**
73 * See taglib documentation.
74 *
75 * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
76 * javax.faces.component.UIComponent)
77 */
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 }