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 javax.faces.application.Application;
22 import javax.faces.component.FacesComponent;
23 import javax.faces.component.UIColumn;
24 import javax.faces.component.UIComponentBase;
25 import javax.faces.component.UIViewRoot;
26 import javax.faces.component.html.HtmlDataTable;
27 import javax.faces.component.html.HtmlOutputText;
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
34 @FacesComponent(value = "com.myapp.UITableComponent")
35 public class UITableComponent extends UIComponentBase implements
36 SystemEventListener
37 {
38
39
40
41
42
43 public UITableComponent()
44 {
45
46 setRendererType("testcomponent");
47
48 FacesContext context = FacesContext.getCurrentInstance();
49 UIViewRoot root = context.getViewRoot();
50
51 root.subscribeToViewEvent(PreRenderViewEvent.class, this);
52 }
53
54
55
56
57
58 @Override
59 public String getFamily()
60 {
61
62 return "com.myapp";
63 }
64
65 public boolean isListenerForSource(Object source)
66 {
67
68 return (source instanceof UIViewRoot);
69 }
70
71 public void processEvent(SystemEvent event) throws AbortProcessingException
72 {
73
74 FacesContext context = FacesContext.getCurrentInstance();
75
76 if (!context.isPostback())
77 {
78
79 Application application = context.getApplication();
80
81 HtmlDataTable dataTable = new HtmlDataTable();
82 dataTable.setVar("_internal");
83 dataTable.setValueExpression(
84 "value",
85 application.getExpressionFactory().createValueExpression(
86 context.getELContext(), "#{testManagedBean.list}",
87 Object.class));
88 getChildren().add(dataTable);
89
90 UIColumn column = new UIColumn();
91 column.setId(context.getViewRoot().createUniqueId());
92 dataTable.getChildren().add(column);
93
94 HtmlOutputText outputText = new HtmlOutputText();
95 outputText.setId(context.getViewRoot().createUniqueId());
96 outputText.setValueExpression(
97 "value",
98 application.getExpressionFactory().createValueExpression(
99 context.getELContext(), "#{_internal}",
100 Object.class));
101 column.getChildren().add(outputText);
102 }
103 }
104 }