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.calendar;
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.shared_tomahawk.util.ClassUtils;
26  
27  /**
28   * 
29   * @since 1.1.10
30   * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
31   * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (miƩ, 03 sep 2008) $
32   */
33  public abstract class AbstractHtmlInputCalendarTag extends 
34      org.apache.myfaces.generated.taglib.html.ext.HtmlInputTextTag
35  {
36      
37      private String _dateBusinessConverter;
38      
39      public void setDateBusinessConverter(String dateBusinessConverter)
40      {
41          _dateBusinessConverter = dateBusinessConverter;
42      }
43  
44      public void release() {
45          super.release();
46          _dateBusinessConverter = null;
47      }
48  
49      /**
50       * Applies attributes to the tree component
51       */
52      protected void setProperties(UIComponent component) {
53          super.setProperties(component);
54          FacesContext context = FacesContext.getCurrentInstance();
55  
56          org.apache.myfaces.custom.calendar.AbstractHtmlInputCalendar comp =
57              (org.apache.myfaces.custom.calendar.AbstractHtmlInputCalendar) component;
58          
59          if (_dateBusinessConverter != null)
60          {
61              if (isValueReference(_dateBusinessConverter))
62              {
63                  ValueBinding vb = context.getApplication().createValueBinding(_dateBusinessConverter);
64                  comp.setValueBinding("dateBusinessConverter", vb);
65              }
66              else
67              {
68                  try
69                  {
70                      Class clazz = ClassUtils.classForName(_dateBusinessConverter);
71                      comp.setDateBusinessConverter( (DateBusinessConverter) ClassUtils.newInstance(clazz));
72                  }
73                  catch(ClassNotFoundException e)
74                  {
75                      throw new IllegalArgumentException("Class referenced in calendarConverter not found: "+_dateBusinessConverter);
76                  }
77                  catch(ClassCastException e)
78                  {
79                      throw new IllegalArgumentException("Class referenced in calendarConverter is not instance of org.apache.myfaces.custom.calendar.CalendarConverter: "+_dateBusinessConverter);
80                  }
81              }
82          }
83      }
84  }