View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.component;
21  
22  import org.apache.myfaces.tobago.component.Attributes;
23  import org.apache.myfaces.tobago.component.Facets;
24  import org.apache.myfaces.tobago.component.OnComponentCreated;
25  import org.apache.myfaces.tobago.renderkit.RendererBase;
26  import org.apache.myfaces.tobago.util.ComponentUtils;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  import javax.faces.component.UIComponent;
31  import javax.faces.context.FacesContext;
32  import javax.faces.event.FacesEvent;
33  import javax.faces.render.Renderer;
34  
35  public abstract class AbstractUIDatePicker extends AbstractUILink implements OnComponentCreated {
36  
37    private static final Logger LOG = LoggerFactory.getLogger(AbstractUIDatePicker.class);
38  
39    public abstract String getFor();
40  
41    public abstract void setDisabled(boolean disabled);
42  
43    public UIComponent getForComponent() {
44      ComponentUtils.evaluateAutoFor(this, AbstractUIDate.class);
45      return ComponentUtils.findFor(this);
46    }
47  
48    public void broadcast(FacesEvent facesEvent) {
49      FacesContext facesContext = FacesContext.getCurrentInstance();
50      UIComponent popup = (UIComponent) getFacets().get(Facets.POPUP);
51      String clientId = getForComponent().getClientId(facesContext);
52      UIComponent box = popup.findComponent("box");
53      UIComponent calendar = box.findComponent("calendar");
54      calendar.getAttributes().put(Attributes.DATE_INPUT_ID, clientId);
55      UIComponent time = box.findComponent("time");
56      if (time != null) {
57        time.getAttributes().put(Attributes.DATE_INPUT_ID, clientId);
58      }
59      super.broadcast(facesEvent);
60    }
61  
62    public void onComponentCreated(FacesContext context, UIComponent parent) {
63      Renderer renderer = getRenderer(getFacesContext());
64      if (renderer instanceof RendererBase) {
65        ((RendererBase) renderer).onComponentCreated(context, this, parent);
66      }
67    }
68  
69    public String getTarget() {
70      return null;
71    }
72  
73    public boolean isTransition() {
74      return true;
75    }
76  
77    public boolean isOmit() {
78      return false;
79    }
80  }