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.Iterator;
22
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.component.html.HtmlInputText;
28 import javax.faces.component.html.HtmlPanelGroup;
29 import javax.faces.context.FacesContext;
30 import javax.faces.event.AbortProcessingException;
31 import javax.faces.event.PreRenderViewEvent;
32 import javax.faces.event.SystemEvent;
33 import javax.faces.event.SystemEventListener;
34
35 @FacesComponent(value = "com.myapp.UIInputComponent")
36 public class UIInputComponent extends UIComponentBase implements
37 SystemEventListener
38 {
39
40
41
42
43
44 public UIInputComponent()
45 {
46
47 setRendererType("testcomponent");
48
49 FacesContext context = FacesContext.getCurrentInstance();
50 UIViewRoot root = context.getViewRoot();
51
52 root.subscribeToViewEvent(PreRenderViewEvent.class, this);
53 }
54
55
56
57
58
59 @Override
60 public String getFamily()
61 {
62
63 return "com.myapp";
64 }
65
66 public boolean isListenerForSource(Object source)
67 {
68
69 return (source instanceof UIViewRoot);
70 }
71
72 public void processEvent(SystemEvent event) throws AbortProcessingException
73 {
74
75 FacesContext context = FacesContext.getCurrentInstance();
76
77 if (!context.isPostback())
78 {
79
80 UIComponent originalComponent = getChildren().remove(0);
81
82 HtmlPanelGroup panelGroup = new HtmlPanelGroup();
83 panelGroup
84 .setStyle("border: 1px dashed blue; padding: 5px; margin: 5px");
85 getChildren().add(panelGroup);
86
87
88
89 panelGroup.getChildren().add(originalComponent);
90 }
91 else
92 {
93
94
95
96 for (Iterator<UIComponent> it = getChildren().iterator(); it
97 .hasNext();)
98 {
99 if (it.next() instanceof HtmlInputText)
100 {
101 it.remove();
102 }
103 }
104 }
105 }
106 }