01: /*
02: * Copyright 2006 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package javax.faces.webapp;
17:
18: import javax.faces.component.EditableValueHolder;
19: import javax.faces.component.UIComponent;
20: import javax.faces.validator.Validator;
21: import javax.servlet.jsp.JspException;
22: import javax.servlet.jsp.tagext.Tag;
23: import javax.servlet.jsp.tagext.TagSupport;
24:
25: /**
26: * @author Manfred Geiler (latest modification by $Author: baranda $)
27: * @version $Revision: 467959 $ $Date: 2006-10-26 13:18:49 +0200 (Do, 26 Okt 2006) $
28: */
29: public abstract class ValidatorELTag extends TagSupport {
30: private static final long serialVersionUID = 8794036166323016663L;
31:
32: public int doStartTag() throws javax.servlet.jsp.JspException {
33: UIComponentClassicTagBase componentTag = UIComponentELTag
34: .getParentUIComponentClassicTagBase(pageContext);
35: if (componentTag == null) {
36: throw new JspException("no parent UIComponentTag found");
37: }
38: if (!componentTag.getCreated()) {
39: return Tag.SKIP_BODY;
40: }
41:
42: Validator validator = createValidator();
43:
44: UIComponent component = componentTag.getComponentInstance();
45: if (component == null) {
46: throw new JspException(
47: "parent UIComponentTag has no UIComponent");
48: }
49: if (!(component instanceof EditableValueHolder)) {
50: throw new JspException(
51: "UIComponent is no EditableValueHolder");
52: }
53: ((EditableValueHolder) component).addValidator(validator);
54:
55: return Tag.SKIP_BODY;
56: }
57:
58: protected abstract Validator createValidator() throws JspException;
59:
60: }
|