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