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.validator;
20  
21  import javax.faces.context.FacesContext;
22  import javax.faces.el.ValueBinding;
23  import javax.faces.validator.Validator;
24  import javax.faces.webapp.UIComponentTag;
25  import javax.faces.webapp.ValidatorTag;
26  import javax.servlet.jsp.JspException;
27  
28  /**
29   * ValidatorBaseTag provides support for ValidatorBase subclasses.
30   * ValidatorBaseTag subclass tld entries should include the following to pick up attribute defintions.
31   *         &ext_validator_base_attributes;
32   * 
33   * @author mkienenb (latest modification by $Author: lu4242 $)
34   * @version $Revision: 680740 $
35   */
36  public class ValidatorBaseTag extends ValidatorTag {
37      private static final long serialVersionUID = 4416508071412794682L;
38      private String _message = null;
39      private String _detailMessage = null;
40      private String _summaryMessage = null;
41  
42      public void setMessage(String string) {
43          _message = string;
44      }
45  
46      public void setDetailMessage(String detailMessage)
47      {
48          _detailMessage = detailMessage;
49      }
50  
51      public void setSummaryMessage(String summaryMessage)
52      {
53          _summaryMessage = summaryMessage;
54      }
55  
56      protected Validator createValidator() throws JspException {
57  
58          ValidatorBase validator = (ValidatorBase)super.createValidator();
59  
60          FacesContext facesContext = FacesContext.getCurrentInstance();
61  
62          if(_message != null && _detailMessage != null)
63              throw new JspException("you may not set message and detailMessage together - they serve the same purpose.");
64  
65          String detailMessage = _message;
66  
67          if(_detailMessage != null)
68              detailMessage = _detailMessage;
69  
70          if (detailMessage != null)
71          {
72              if (UIComponentTag.isValueReference(detailMessage))
73              {
74                  ValueBinding vb = facesContext.getApplication().createValueBinding(detailMessage);
75                  validator.setValueBinding("detailMessage",vb);
76              }
77              else
78              {
79                  validator.setDetailMessage(detailMessage);
80              }
81          }
82  
83          if (_summaryMessage != null)
84          {
85              if (UIComponentTag.isValueReference(_summaryMessage))
86              {
87                  ValueBinding vb = facesContext.getApplication().createValueBinding(_summaryMessage);
88                  validator.setValueBinding("summaryMessage",vb);
89              }
90              else
91              {
92                  validator.setSummaryMessage(_summaryMessage);
93              }
94          }
95  
96          return validator;
97      }
98  
99      public void release()
100     {
101         super.release();
102         _message= null;
103         _detailMessage = null;
104         _summaryMessage = null;
105     }
106 }