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.view.facelets.tag.jsf.core;
20  
21  import javax.el.ELException;
22  import javax.faces.FacesException;
23  import javax.faces.convert.Converter;
24  import javax.faces.view.facelets.ConverterConfig;
25  import javax.faces.view.facelets.ConverterHandler;
26  import javax.faces.view.facelets.FaceletContext;
27  import javax.faces.view.facelets.FaceletException;
28  import javax.faces.view.facelets.MetaRuleset;
29  import javax.faces.view.facelets.TagAttribute;
30  
31  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
32  
33  /**
34   * Register a named Converter instance on the UIComponent associated with the closest parent UIComponent custom action.
35   * <p/> See <a target="_new" href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/tlddocs/f/converter.html">tag
36   * documentation</a>.
37   * 
38   * @author Jacob Hookom
39   * @version $Id$
40   */
41  @JSFFaceletTag(
42          name = "f:converter",
43          bodyContent = "empty", 
44          tagClass="org.apache.myfaces.taglib.core.ConverterImplTag")
45  public final class ConvertDelegateHandler extends ConverterHandler
46  {
47  
48      private final TagAttribute converterId;
49  
50      /**
51       * @param config
52       */
53      public ConvertDelegateHandler(ConverterConfig config)
54      {
55          super(config);
56          this.converterId = this.getAttribute("converterId");
57      }
58  
59      /**
60       * Uses the specified "converterId" to pull an instance from the Application
61       * 
62       * @see javax.faces.application.Application#createComponent(java.lang.String)
63       * @see org.apache.myfaces.view.facelets.tag.jsf.ConverterHandler#createConverter(javax.faces.view.facelets.FaceletContext)
64       */
65      protected Converter createConverter(FaceletContext ctx) throws FacesException, ELException, FaceletException
66      {
67          return ctx.getFacesContext().getApplication().createConverter(this.getConverterId(ctx));
68      }
69  
70      protected MetaRuleset createMetaRuleset(Class type)
71      {
72          return super.createMetaRuleset(type).ignoreAll();
73      }
74  
75      @Override
76      public String getConverterId(FaceletContext ctx)
77      {
78          if (converterId == null)
79          {
80              return null;
81          }
82          return converterId.getValue(ctx);
83      }
84  }