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.commons.converter;
20  
21  import javax.el.ValueExpression;
22  import javax.faces.context.FacesContext;
23  import javax.faces.convert.Converter;
24  import javax.servlet.jsp.JspException;
25  
26  /**
27   * ConverterBaseTag provides support for ConverterBase subclasses.
28   * ConverterBaseTag subclass tld entries should include the following to pick up attribute defintions.
29   *         &ext_converter_base_attributes;
30   * 
31   * @author mkienenb (latest modification by $Author: lu4242 $)
32   * @version $Revision: 706423 $
33   */
34  public abstract class ConverterBaseTag extends ConverterTag {
35      private static final long serialVersionUID = 4416508071412794682L;
36      private ValueExpression _detailMessage = null;
37      private ValueExpression _summaryMessage = null;
38  
39      public void setDetailMessage(ValueExpression detailMessage)
40      {
41          _detailMessage = detailMessage;
42      }
43  
44      public void setSummaryMessage(ValueExpression summaryMessage)
45      {
46          _summaryMessage = summaryMessage;
47      }
48  
49      protected Converter createConverter() throws JspException
50      {
51          ConverterBase converter = (ConverterBase) super.createConverter();
52          
53          FacesContext facesContext = FacesContext.getCurrentInstance();
54  
55          if (_detailMessage != null)
56          {
57              if (!_detailMessage.isLiteralText())
58              {
59                  converter.setValueExpression("detailMessage",_detailMessage);
60              }
61              else
62              {
63                  converter.setDetailMessage((String)_detailMessage.getValue(facesContext.getELContext()));
64              }
65          }
66  
67          if (_summaryMessage != null)
68          {
69              if (!_summaryMessage.isLiteralText())
70              {
71                  converter.setValueExpression("summaryMessage",_summaryMessage);
72              }
73              else
74              {
75                  converter.setSummaryMessage((String)_summaryMessage.getValue(facesContext.getELContext()));
76              }
77          }
78          
79          return converter;
80      }
81      
82      public void release()
83      {
84          super.release();
85          _detailMessage = null;
86          _summaryMessage = null;
87      }
88  }