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