KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > facelets > tag > jsf > core > FacetHandler


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 JavaDoc;
18
19 import javax.el.ELException;
20 import javax.faces.FacesException;
21 import javax.faces.component.UIComponent;
22 import javax.faces.component.UIComponentBase;
23
24 import com.sun.facelets.FaceletContext;
25 import com.sun.facelets.FaceletException;
26 import com.sun.facelets.tag.TagAttribute;
27 import com.sun.facelets.tag.TagConfig;
28 import com.sun.facelets.tag.TagException;
29 import com.sun.facelets.tag.TagHandler;
30
31 /**
32  * Register a named facet on the UIComponent associated with the closest parent
33  * UIComponent custom action. <p/> See <a target="_new"
34  * HREF="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/tlddocs/f/facet.html">tag
35  * documentation</a>.
36  *
37  * @author Jacob Hookom
38  * @version $Id: FacetHandler.java,v 1.3 2005/12/04 21:02:42 jhook Exp $
39  */

40 public final class FacetHandler extends TagHandler {
41
42     /**
43      * A UIComponent for capturing a child UIComponent, representative of the
44      * desired Facet
45      *
46      * @author Jacob Hookom
47      *
48      */

49     private final static class UIFacet extends UIComponentBase {
50         public String JavaDoc getFamily() {
51             return null;
52         }
53     }
54
55     protected final TagAttribute name;
56
57     public FacetHandler(TagConfig config) {
58         super(config);
59         this.name = this.getRequiredAttribute("name");
60     }
61
62     /* (non-Javadoc)
63      * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext, javax.faces.component.UIComponent)
64      */

65     public void apply(FaceletContext ctx, UIComponent parent)
66             throws IOException JavaDoc, FacesException, FaceletException, ELException {
67         UIFacet facet = new UIFacet();
68         String JavaDoc name = this.name.getValue(ctx);
69         UIComponent oldFacetChild = (UIComponent) parent.getFacets().remove(name);
70         if (oldFacetChild != null) {
71             facet.getChildren().add(oldFacetChild);
72         }
73         this.nextHandler.apply(ctx, facet);
74         int childCount = facet.getChildCount();
75         UIComponent c;
76         if (childCount == 1) {
77             c = (UIComponent) facet.getChildren().get(0);
78             parent.getFacets().put(name, c);
79         } else {
80             throw new TagException(this.tag, "Facet Tag can only have one child UIComponent");
81         }
82     }
83 }
84
Popular Tags