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 | 0 | super(config); |
49 | 0 | } |
50 | |
|
51 | |
public void apply(FaceletContext ctx, UIComponent parent) |
52 | |
throws IOException |
53 | |
{ |
54 | 0 | if (parent == null) |
55 | |
{ |
56 | 0 | throw new TagException(this.tag, "Parent UIComponent was null"); |
57 | |
} |
58 | 0 | if (! (parent instanceof UIViewRoot) ) |
59 | |
{ |
60 | 0 | throw new TagException(this.tag, "Parent UIComponent "+parent.getId()+" should be instance of UIViewRoot"); |
61 | |
} |
62 | 0 | FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(ctx); |
63 | 0 | if (mctx.isBuildingViewMetadata()) |
64 | |
{ |
65 | 0 | UIComponent metadataFacet = parent.getFacet(UIViewRoot.METADATA_FACET_NAME); |
66 | 0 | if (metadataFacet == null) |
67 | |
{ |
68 | 0 | metadataFacet = ctx.getFacesContext().getApplication().createComponent( |
69 | |
ctx.getFacesContext(), UIPanel.COMPONENT_TYPE, null); |
70 | 0 | metadataFacet.setId(UIViewRoot.METADATA_FACET_NAME); |
71 | 0 | metadataFacet.getAttributes().put(ComponentSupport.FACET_CREATED_UIPANEL_MARKER, true); |
72 | 0 | metadataFacet.getAttributes().put(ComponentSupport.COMPONENT_ADDED_BY_HANDLER_MARKER, Boolean.TRUE); |
73 | 0 | parent.getFacets().put(UIViewRoot.METADATA_FACET_NAME, metadataFacet); |
74 | |
} |
75 | |
} |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | 0 | parent.getAttributes().put(FacetHandler.KEY, UIViewRoot.METADATA_FACET_NAME); |
82 | 0 | mctx.startMetadataSection(); |
83 | |
try |
84 | |
{ |
85 | 0 | this.nextHandler.apply(ctx, parent); |
86 | |
} |
87 | |
finally |
88 | |
{ |
89 | 0 | mctx.endMetadataSection(); |
90 | 0 | parent.getAttributes().remove(FacetHandler.KEY); |
91 | 0 | } |
92 | 0 | } |
93 | |
} |