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 javax.faces.webapp;
20  
21  import javax.faces.application.Application;
22  import javax.faces.component.UIComponent;
23  import javax.faces.component.ValueHolder;
24  import javax.faces.context.FacesContext;
25  import javax.faces.convert.Converter;
26  import javax.faces.el.ValueBinding;
27  import javax.servlet.jsp.JspException;
28  import javax.servlet.jsp.tagext.Tag;
29  import javax.servlet.jsp.tagext.TagSupport;
30  
31  /**
32   * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
33   *
34   * @author Manfred Geiler (latest modification by $Author: skitching $)
35   * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Sun, 13 Jul 2008) $
36   * @deprecated replaced by {@link ConverterELTag}
37   */
38  public class ConverterTag
39          extends TagSupport
40  {
41      private static final long serialVersionUID = -6168345066829108081L;
42      private String _converterId;
43      private String _binding;
44  
45      public ConverterTag()
46      {
47          super();
48      }
49  
50      public void setConverterId(String converterId)
51      {
52          _converterId = converterId;
53      }
54  
55      public int doStartTag()
56              throws JspException
57      {
58  
59          UIComponentClassicTagBase componentTag = UIComponentClassicTagBase.getParentUIComponentClassicTagBase(pageContext);
60  
61          if (componentTag == null)
62          {
63              throw new JspException("no parent UIComponentTag found");
64          }
65          if (!componentTag.getCreated())
66          {
67              return Tag.SKIP_BODY;
68          }
69  
70          Converter converter = createConverter();
71  
72          UIComponent component = componentTag.getComponentInstance();
73          if (component == null)
74          {
75              throw new JspException("parent UIComponentTag has no UIComponent");
76          }
77          if (!(component instanceof ValueHolder))
78          {
79              throw new JspException("UIComponent is no ValueHolder");
80          }
81          ((ValueHolder)component).setConverter(converter);
82  
83          return Tag.SKIP_BODY;
84      }
85  
86      public void release()
87      {
88          super.release();
89          _converterId = null;
90          _binding = null;
91      }
92  
93      protected Converter createConverter()
94              throws JspException
95      {
96          FacesContext facesContext = FacesContext.getCurrentInstance();
97          Application application = facesContext.getApplication();
98  
99          if(_binding != null) {
100             ValueBinding vb = application.createValueBinding(_binding);
101             if(vb != null) {
102                 Converter converter = (Converter) vb.getValue(facesContext);
103                 if(converter != null) {
104                     return converter;
105                 }
106             }
107         }
108 
109         if (UIComponentTag.isValueReference(_converterId))
110         {
111             ValueBinding vb = facesContext.getApplication().createValueBinding(_converterId);
112             return application.createConverter((String)vb.getValue(facesContext));
113         }
114 
115         return application.createConverter(_converterId);
116 
117     }
118 
119     public void setBinding(String binding) throws javax.servlet.jsp.JspException
120     {
121         _binding = binding;
122     }
123 }