01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.markup.html.form.validation;
18:
19: import org.apache.wicket.Session;
20: import org.apache.wicket.feedback.ContainerFeedbackMessageFilter;
21: import org.apache.wicket.feedback.IFeedback;
22: import org.apache.wicket.feedback.IFeedbackMessageFilter;
23: import org.apache.wicket.markup.html.WebMarkupContainer;
24: import org.apache.wicket.markup.html.border.Border;
25:
26: /**
27: * A border that can be placed around a form component to indicate when the
28: * bordered child/children has a validation error. A child of the border named
29: * "errorIndicator" will be shown and hidden depending on whether the child has
30: * an error. A typical error indicator might be a little red asterisk.
31: * <p>
32: * <strong>Note: </strong> Since this border checks its children do not use
33: * setTransparentResolver(true) and add the children directly into the border
34: *
35: * @author Jonathan Locke
36: * @author Eelco Hillenius
37: */
38: public class FormComponentFeedbackBorder extends Border implements
39: IFeedback {
40: private static final long serialVersionUID = 1L;
41:
42: /** Visible property cache. */
43: private boolean visible;
44:
45: /**
46: * Error indicator that will be shown whenever there is an error-level
47: * message for the collecting component.
48: */
49: private final class ErrorIndicator extends WebMarkupContainer {
50: private static final long serialVersionUID = 1L;
51:
52: /**
53: * Construct.
54: *
55: * @param id
56: * component id
57: */
58: public ErrorIndicator(String id) {
59: super (id);
60: }
61:
62: /**
63: * @see org.apache.wicket.Component#isVisible()
64: */
65: public boolean isVisible() {
66: return visible;
67: }
68: }
69:
70: /**
71: * Constructor.
72: *
73: * @param id
74: * See Component
75: */
76: public FormComponentFeedbackBorder(final String id) {
77: super (id);
78: add(new ErrorIndicator("errorIndicator"));
79: }
80:
81: /**
82: * @see org.apache.wicket.feedback.IFeedback#updateFeedback()
83: */
84: public void updateFeedback() {
85: // Get the messages for the current page
86: visible = Session.get().getFeedbackMessages().messages(
87: getMessagesFilter()).size() != 0;
88: }
89:
90: /**
91: * @return Let subclass specify some other filter
92: */
93: protected IFeedbackMessageFilter getMessagesFilter() {
94: return new ContainerFeedbackMessageFilter(this);
95: }
96: }
|