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  package org.apache.myfaces.custom.date;
20  
21  import javax.faces.component.UIComponent;
22  import javax.faces.context.FacesContext;
23  import javax.faces.el.ValueBinding;
24  
25  import org.apache.myfaces.custom.calendar.DateBusinessConverter;
26  import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
27  
28  /**
29   * <p>
30   * HtmlTree tag.
31   * </p>
32   * @since 1.1.7
33   * @author <a href="mailto:oliver@rossmueller.com">Oliver Rossmueller </a>
34   * @version $Revision: 888604 $ $Date: 2004/10/13 11:50:58
35   */
36  public abstract class AbstractHtmlInputDateTag extends 
37      org.apache.myfaces.shared_tomahawk.taglib.html.HtmlInputTextTag
38  {
39      
40      private String _dateBusinessConverter;
41      
42      public void setDateBusinessConverter(String dateBusinessConverter)
43      {
44          _dateBusinessConverter = dateBusinessConverter;
45      }
46  
47      public void release() {
48          super.release();
49          _dateBusinessConverter = null;
50      }
51  
52      /**
53       * Applies attributes to the tree component
54       */
55      protected void setProperties(UIComponent component) {
56          super.setProperties(component);
57          FacesContext context = FacesContext.getCurrentInstance();
58  
59          org.apache.myfaces.custom.date.AbstractHtmlInputDate comp =
60              (org.apache.myfaces.custom.date.AbstractHtmlInputDate) component;
61          
62          if (_dateBusinessConverter != null)
63          {
64              if (isValueReference(_dateBusinessConverter))
65              {
66                  ValueBinding vb = context.getApplication().createValueBinding(_dateBusinessConverter);
67                  comp.setValueBinding("dateBusinessConverter", vb);
68              }
69              else
70              {
71                  try
72                  {
73                      Class clazz = ClassUtils.classForName(_dateBusinessConverter);
74                      comp.setDateBusinessConverter( (DateBusinessConverter) ClassUtils.newInstance(clazz));
75                  }
76                  catch(ClassNotFoundException e)
77                  {
78                      throw new IllegalArgumentException("Class referenced in calendarConverter not found: "+_dateBusinessConverter);
79                  }
80                  catch(ClassCastException e)
81                  {
82                      throw new IllegalArgumentException("Class referenced in calendarConverter is not instance of org.apache.myfaces.custom.calendar.CalendarConverter: "+_dateBusinessConverter);
83                  }
84              }
85          }
86      }
87  }