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