Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/sun/facelets/tag/jsf/core/ConvertNumberHandler.java


1   /**
2    * Licensed under the Common Development and Distribution License,
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    * 
6    *   http://www.sun.com/cddl/
7    *   
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
11   * implied. See the License for the specific language governing
12   * permissions and limitations under the License.
13   */
14  
15  package com.sun.facelets.tag.jsf.core;
16  
17  import javax.el.ELException;
18  import javax.faces.FacesException;
19  import javax.faces.convert.Converter;
20  import javax.faces.convert.NumberConverter;
21  
22  import com.sun.facelets.FaceletContext;
23  import com.sun.facelets.FaceletException;
24  import com.sun.facelets.tag.TagAttribute;
25  import com.sun.facelets.tag.MetaRuleset;
26  import com.sun.facelets.tag.jsf.ComponentSupport;
27  import com.sun.facelets.tag.jsf.ConvertHandler;
28  import com.sun.facelets.tag.jsf.ConverterConfig;
29  
30  /**
31   * Register a NumberConverter instance on the UIComponent associated with the
32   * closest parent UIComponent custom action. <p/> See <a target="_new"
33   * href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/tlddocs/f/convertNumber.html">tag
34   * documentation</a>.
35   * 
36   * @author Jacob Hookom
37   * @version $Id: ConvertNumberHandler.java,v 1.3 2005/08/24 04:38:49 jhook Exp $
38   */
39  public final class ConvertNumberHandler extends ConvertHandler {
40  
41      private final TagAttribute locale;
42  
43      /**
44       * @param config
45       */
46      public ConvertNumberHandler(ConverterConfig config) {
47          super(config);
48          this.locale = this.getAttribute("locale");
49      }
50  
51      /**
52       * Returns a new NumberConverter
53       * 
54       * @see NumberConverter
55       * @see com.sun.facelets.tag.jsf.ConverterHandler#createConverter(com.sun.facelets.FaceletContext)
56       */
57      protected Converter createConverter(FaceletContext ctx)
58              throws FacesException, ELException, FaceletException {
59          return ctx.getFacesContext().getApplication().createConverter(NumberConverter.CONVERTER_ID);
60      }
61  
62      /* (non-Javadoc)
63       * @see com.sun.facelets.tag.ObjectHandler#setAttributes(com.sun.facelets.FaceletContext, java.lang.Object)
64       */
65      protected void setAttributes(FaceletContext ctx, Object obj) {
66          super.setAttributes(ctx, obj);
67          NumberConverter c = (NumberConverter) obj;
68          if (this.locale != null) {
69              c.setLocale(ComponentSupport.getLocale(ctx, this.locale));
70          }
71      }
72  
73      protected MetaRuleset createMetaRuleset(Class type) {
74          return super.createMetaRuleset(type).ignore("locale");
75      }
76  
77  }