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.pss.acid.component;
20
21 import java.util.HashMap;
22 import java.util.Map;
23 import javax.faces.component.FacesComponent;
24 import javax.faces.component.UIComponent;
25 import javax.faces.component.UIComponentBase;
26 import javax.faces.component.UIOutput;
27 import javax.faces.component.UIViewRoot;
28 import javax.faces.context.FacesContext;
29 import javax.faces.event.AbortProcessingException;
30 import javax.faces.event.PreRenderViewEvent;
31 import javax.faces.event.SystemEvent;
32 import javax.faces.event.SystemEventListener;
33 import javax.faces.view.ViewDeclarationLanguage;
34
35 @FacesComponent(value = "com.myapp.UIAddSimpleCCVDL3", createTag=true,
36 namespace="http://testcomponent", tagName="addSimpleCCVDL3")
37 public class UIAddSimpleCCVDL3 extends UIComponentBase implements
38 SystemEventListener
39 {
40
41
42
43
44
45 public UIAddSimpleCCVDL3()
46 {
47 setRendererType(null);
48
49 FacesContext context = FacesContext.getCurrentInstance();
50 UIViewRoot root = context.getViewRoot();
51 if (root != null)
52 {
53 root.subscribeToViewEvent(PreRenderViewEvent.class, this);
54 }
55 }
56
57
58
59
60
61 @Override
62 public String getFamily()
63 {
64
65 return "com.myapp";
66 }
67
68 public boolean isListenerForSource(Object source)
69 {
70
71 return (source instanceof UIViewRoot);
72 }
73
74 public void processEvent(SystemEvent event) throws AbortProcessingException
75 {
76 FacesContext facesContext = FacesContext.getCurrentInstance();
77 if (!facesContext.isPostback())
78 {
79 ViewDeclarationLanguage vdl = facesContext.getApplication().
80 getViewHandler().getViewDeclarationLanguage(
81 facesContext, facesContext.getViewRoot().getViewId());
82
83 Map<String, Object> attributes = new HashMap<String, Object>();
84 UIComponent component = vdl.createComponent(facesContext,
85 "http://java.sun.com/jsf/composite/testComposite",
86 "dynComp_3", attributes);
87 UIOutput text = (UIOutput) facesContext.getApplication().
88 createComponent(UIOutput.COMPONENT_TYPE);
89 text.setValue("Dynamically added header");
90 component.getChildren().add(text);
91
92 getChildren().add(component);
93 }
94 }
95 }