1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.tag.jsf.core;
20
21 import java.io.IOException;
22
23 import javax.faces.component.UIComponent;
24 import javax.faces.component.UIPanel;
25 import javax.faces.component.UIViewRoot;
26 import javax.faces.view.facelets.FaceletContext;
27 import javax.faces.view.facelets.TagConfig;
28 import javax.faces.view.facelets.TagException;
29 import javax.faces.view.facelets.TagHandler;
30
31 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
32 import org.apache.myfaces.view.facelets.FaceletCompositionContext;
33 import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
34
35
36
37
38
39
40
41
42 @JSFFaceletTag(name="f:metadata")
43 public final class ViewMetadataHandler extends TagHandler
44 {
45
46 public ViewMetadataHandler(TagConfig config)
47 {
48 super(config);
49 }
50
51 public void apply(FaceletContext ctx, UIComponent parent)
52 throws IOException
53 {
54 if (parent == null)
55 {
56 throw new TagException(this.tag, "Parent UIComponent was null");
57 }
58 if (! (parent instanceof UIViewRoot) )
59 {
60 throw new TagException(this.tag, "Parent UIComponent "+parent.getId()+" should be instance of UIViewRoot");
61 }
62 FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx);
63 if (mctx.isBuildingViewMetadata())
64 {
65 UIComponent metadataFacet = parent.getFacet(UIViewRoot.METADATA_FACET_NAME);
66 if (metadataFacet == null)
67 {
68 metadataFacet = ctx.getFacesContext().getApplication().createComponent(
69 ctx.getFacesContext(), UIPanel.COMPONENT_TYPE, null);
70 metadataFacet.setId(UIViewRoot.METADATA_FACET_NAME);
71 metadataFacet.getAttributes().put(ComponentSupport.FACET_CREATED_UIPANEL_MARKER, true);
72 metadataFacet.getAttributes().put(ComponentSupport.COMPONENT_ADDED_BY_HANDLER_MARKER, Boolean.TRUE);
73 parent.getFacets().put(UIViewRoot.METADATA_FACET_NAME, metadataFacet);
74 }
75 }
76
77
78
79
80
81 parent.getAttributes().put(FacetHandler.KEY, UIViewRoot.METADATA_FACET_NAME);
82 mctx.startMetadataSection();
83 try
84 {
85 this.nextHandler.apply(ctx, parent);
86 }
87 finally
88 {
89 mctx.endMetadataSection();
90 parent.getAttributes().remove(FacetHandler.KEY);
91 }
92 }
93 }