1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.facelets.extension;
21
22 import org.apache.myfaces.tobago.component.OnComponentCreated;
23 import org.apache.myfaces.tobago.component.RendererTypes;
24 import org.apache.myfaces.tobago.component.UIDate;
25 import org.apache.myfaces.tobago.component.UIDatePicker;
26 import org.apache.myfaces.tobago.component.UIForm;
27 import org.apache.myfaces.tobago.util.ComponentUtils;
28
29 import javax.faces.application.Application;
30 import javax.faces.component.UIComponent;
31 import javax.faces.component.UIViewRoot;
32 import javax.faces.view.facelets.ComponentConfig;
33 import javax.faces.view.facelets.FaceletContext;
34 import javax.faces.view.facelets.TagAttribute;
35
36 public class DateExtensionHandler extends TobagoLabelExtensionHandler {
37
38 private TagAttribute pickerIdAttribute;
39 private TagAttribute formIdAttribute;
40
41 public DateExtensionHandler(ComponentConfig config) {
42 super(config);
43 pickerIdAttribute = getAttribute("pickerId");
44 formIdAttribute = getAttribute("formId");
45 }
46
47 protected String getSubComponentType() {
48 return UIDate.COMPONENT_TYPE;
49 }
50
51 protected String getSubRendererType() {
52 return RendererTypes.DATE;
53 }
54
55 public void onComponentPopulated(FaceletContext faceletContext, UIComponent panel, UIComponent parent) {
56 super.onComponentPopulated(faceletContext, panel, parent);
57 if (panel.getChildCount() == 2) {
58 Application application = faceletContext.getFacesContext().getApplication();
59 UIViewRoot root = ComponentUtils.findViewRoot(faceletContext, parent);
60
61 UIForm form = (UIForm) application.createComponent(UIForm.COMPONENT_TYPE);
62 form.setRendererType(RendererTypes.FORM);
63 form.setId(formIdAttribute != null ? formIdAttribute.getValue(faceletContext) : root.createUniqueId());
64 panel.getChildren().add(form);
65
66 UIDatePicker picker = (UIDatePicker) application.createComponent(UIDatePicker.COMPONENT_TYPE);
67 picker.setRendererType(RendererTypes.DATE_PICKER);
68 picker.setFor("@auto");
69 picker.setId(pickerIdAttribute != null ? pickerIdAttribute.getValue(faceletContext) : root.createUniqueId());
70 if (picker.getAttributes().get(OnComponentCreated.MARKER) == null) {
71 picker.getAttributes().put(OnComponentCreated.MARKER, Boolean.TRUE);
72 picker.onComponentCreated(faceletContext.getFacesContext(), panel);
73 }
74 form.getChildren().add(picker);
75 }
76 }
77
78 protected String getColumns(String first) {
79 return first + ";*;auto";
80 }
81 }