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.el.ValueExpression;
22  import javax.faces.component.UIComponent;
23  import javax.faces.context.FacesContext;
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 ValueExpression _dateBusinessConverter;
41      
42      public void setDateBusinessConverter( ValueExpression 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 (!_dateBusinessConverter.isLiteralText())
65              {
66                  comp.setValueExpression("dateBusinessConverter", _dateBusinessConverter);
67              }
68              else
69              {
70                  String s = _dateBusinessConverter.getExpressionString();
71                  if (s != null)
72                  {            
73                      try
74                      {
75                          Class clazz = ClassUtils.classForName(s);
76                          comp.setDateBusinessConverter( (DateBusinessConverter) ClassUtils.newInstance(clazz));
77                      }
78                      catch(ClassNotFoundException e)
79                      {
80                          throw new IllegalArgumentException("Class referenced in calendarConverter not found: "+_dateBusinessConverter);
81                      }
82                      catch(ClassCastException e)
83                      {
84                          throw new IllegalArgumentException("Class referenced in calendarConverter is not instance of org.apache.myfaces.custom.calendar.CalendarConverter: "+_dateBusinessConverter);
85                      }
86                  }
87              }
88          }
89      }
90  }