2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shale.validator.tag;
19  
20  import java.util.Locale;
21  
22  import javax.faces.context.FacesContext;
23  import javax.faces.convert.Converter;
24  import javax.faces.el.ValueBinding;
25  import javax.faces.webapp.ConverterTag;
26  import javax.faces.webapp.UIComponentTag;
27  
28  import org.apache.shale.util.ConverterHelper;
29  import org.apache.shale.validator.converter.FloatConverter;
30  
31  /***
32   * <p>JSP custom action for <code>FloatConverter</code>.</p>
33   */
34  public final class FloatConverterTag extends ConverterTag {
35      
36      
37      // -------------------------------------------------------- Static Variables
38  
39  
40      /***
41       * Serial version UID.
42       */
43      private static final long serialVersionUID = 1L;
44  
45  
46      /***
47       * <p>Helper object for performing conversions.</p>
48       */
49      private static final ConverterHelper HELPER =
50              new ConverterHelper();
51  
52  
53      // -------------------------------------------------------------- Properties
54  
55  
56      private String locale = null;
57      public void setLocale(String locale) {
58          this.locale = locale;
59      }
60  
61  
62      private String message = null;
63      public void setMessage(String message) {
64          this.message = message;
65      }
66  
67  
68      private String pattern = null;
69      public void setPattern(String pattern) {
70          this.pattern = pattern;
71      }
72  
73  
74      // ------------------------------------------------------------- Tag Methods
75  
76  
77      /***
78       * <p>Release resources allocated for this instance.</p>
79       */
80      public void release() {
81  
82          locale = null;
83          message = null;
84          pattern = null;
85  
86          super.release();
87  
88      }
89  
90  
91      // ---------------------------------------------------- ConverterTag Methods
92  
93  
94      /***
95       * <p>Create and return a new <code>Converter</code> instance to be
96       * registered on our corresponding <code>UIComponent</code>.</p>
97       */
98      protected Converter createConverter() {
99  
100         FacesContext context = FacesContext.getCurrentInstance();
101         FloatConverter converter = new FloatConverter();
102 
103         if (locale != null) {
104             Locale value = null;
105             if (UIComponentTag.isValueReference(locale)) {
106                 ValueBinding vb = context.getApplication().createValueBinding(locale);
107                 value = (Locale) vb.getValue(context);
108             } else {
109                 value = (Locale) HELPER.asObject(context, Locale.class, locale);
110             }
111             converter.setLocale(value);
112         }
113 
114         if (pattern != null) {
115             String value = null;
116             if (UIComponentTag.isValueReference(message)) {
117                 ValueBinding vb = context.getApplication().createValueBinding(pattern);
118                 value = (String) vb.getValue(context);
119             } else {
120                 value = pattern;
121             }
122             converter.setPattern(value);
123         }
124 
125         return converter;
126 
127     }
128 
129 
130 }