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