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.managed;
20
21 import java.util.HashMap;
22 import java.util.Map;
23 import javax.faces.bean.ManagedBean;
24 import javax.faces.bean.RequestScoped;
25 import javax.faces.component.UIComponent;
26 import javax.faces.component.UIOutput;
27 import javax.faces.component.UIPanel;
28 import javax.faces.component.html.HtmlPanelGroup;
29 import javax.faces.context.FacesContext;
30 import javax.faces.view.ViewDeclarationLanguage;
31
32
33
34
35
36 @ManagedBean(name="componentBindingVDLBean4")
37 @RequestScoped
38 public class ComponentBindingVDLBean4
39 {
40 private UIPanel panel;
41
42 public UIPanel getPanel()
43 {
44 if (panel == null)
45 {
46 panel = new HtmlPanelGroup();
47 FacesContext facesContext = FacesContext.getCurrentInstance();
48 if (facesContext.isPostback())
49 {
50
51
52
53 UIOutput out2 = new UIOutput();
54 out2.setValue("hello2");
55 panel.getChildren().add(out2);
56 }
57 UIOutput out = new UIOutput();
58 out.setValue("hello1");
59 panel.getChildren().add(out);
60
61 ViewDeclarationLanguage vdl = facesContext.getApplication().
62 getViewHandler().getViewDeclarationLanguage(
63 facesContext, facesContext.getViewRoot().getViewId());
64
65 Map<String, Object> attributes = new HashMap<String, Object>();
66 UIComponent cc = vdl.createComponent(facesContext,
67 "http://java.sun.com/jsf/composite/testComposite",
68 "dynComp_4", attributes);
69 UIOutput text = (UIOutput) facesContext.getApplication().
70 createComponent(UIOutput.COMPONENT_TYPE);
71 text.setValue("Dynamically added header");
72 cc.getChildren().add(text);
73 panel.getChildren().add(cc);
74
75 if (!facesContext.isPostback())
76 {
77
78 panel.getAttributes().put("attr1", "value1");
79 panel.getChildren().get(0).getAttributes().put("attr2", "value2");
80 }
81 else
82 {
83
84 panel.getAttributes().remove("attr1");
85 panel.getChildren().get(0).getAttributes().remove("attr2");
86 }
87 }
88 return panel;
89 }
90
91 public void setPanel(UIPanel panel)
92 {
93 this.panel = panel;
94 }
95 }