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.Component;
20: import org.apache.wicket.Session;
21: import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
22: import org.apache.wicket.feedback.IFeedback;
23: import org.apache.wicket.feedback.IFeedbackMessageFilter;
24: import org.apache.wicket.markup.html.panel.Panel;
25: import org.apache.wicket.model.IModel;
26:
27: /**
28: * A panel that hides or shows itself depending on whether there are feedback
29: * messages for a given message filter. If a component is set using
30: * setIndicatorFor(Component), then the indicator is visible when the given
31: * component has an error. The default content for this indicator is a red star,
32: * but you can subclass this panel and provide your own markup to give any
33: * custom look you desire.
34: *
35: * @author Jonathan Locke
36: */
37: public class FormComponentFeedbackIndicator extends Panel implements
38: IFeedback {
39: private static final long serialVersionUID = 1L;
40:
41: /** The message filter for this indicator component */
42: private IFeedbackMessageFilter filter;
43:
44: /**
45: * Constructor
46: *
47: * @param id
48: * See Component
49: */
50: public FormComponentFeedbackIndicator(final String id) {
51: super (id);
52: }
53:
54: /**
55: * @see org.apache.wicket.Component#Component(String, IModel)
56: */
57: public FormComponentFeedbackIndicator(final String id, IModel model) {
58: super (id, model);
59: }
60:
61: /**
62: * @param component
63: * The component to watch for messages
64: */
65: public void setIndicatorFor(final Component component) {
66: filter = new ComponentFeedbackMessageFilter(component);
67: }
68:
69: /**
70: * @see org.apache.wicket.feedback.IFeedback#updateFeedback()
71: */
72: public void updateFeedback() {
73: // Get the messages for the current page
74: setVisible(Session.get().getFeedbackMessages().hasMessage(
75: getFeedbackMessageFilter()));
76: }
77:
78: /**
79: * @return Let subclass specify some other filter
80: */
81: protected IFeedbackMessageFilter getFeedbackMessageFilter() {
82: return filter;
83: }
84: }
|