KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > vlib > VirtualLibraryDelegate


1 // Copyright 2004 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.vlib;
16
17 import org.apache.tapestry.IMarkupWriter;
18 import org.apache.tapestry.IRequestCycle;
19 import org.apache.tapestry.form.IFormComponent;
20 import org.apache.tapestry.valid.IValidator;
21 import org.apache.tapestry.valid.ValidationDelegate;
22
23 /**
24  * Implementation of {@link org.apache.tapestry.valid.IValidationDelegate}
25  * which uses the
26  * correct CSS class when rendering errors.
27  *
28  * @author Howard Lewis Ship
29  * @version $Id: VirtualLibraryDelegate.java,v 1.3 2004/02/19 17:37:49 hlship Exp $
30  *
31  **/

32
33 public class VirtualLibraryDelegate extends ValidationDelegate
34 {
35     public void writeLabelPrefix(
36         IFormComponent component,
37         IMarkupWriter writer,
38         IRequestCycle cycle)
39     {
40         if (isInError(component))
41         {
42             writer.begin("span");
43             writer.attribute("class", "invalid-field");
44         }
45     }
46
47     public void writeLabelSuffix(
48         IFormComponent component,
49         IMarkupWriter writer,
50         IRequestCycle cycle)
51     {
52         if (isInError(component))
53             writer.end();
54     }
55
56     public void writeAttributes(
57         IMarkupWriter writer,
58         IRequestCycle cycle,
59         IFormComponent component,
60         IValidator validator)
61     {
62         if (isInError())
63             writer.attribute("class", "error");
64     }
65
66
67     public void writeSuffix(
68         IMarkupWriter writer,
69         IRequestCycle cycle,
70         IFormComponent component,
71         IValidator validator)
72     {
73     }
74
75 }
Popular Tags