01: /*
02: * Copyright 2002-2005 the original author or authors.
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:
17: package info.jtrac.wicket;
18:
19: import java.util.HashSet;
20: import java.util.Set;
21: import org.apache.wicket.feedback.FeedbackMessage;
22: import org.apache.wicket.feedback.IFeedbackMessageFilter;
23: import org.apache.wicket.markup.html.form.ValidationErrorFeedback;
24:
25: /**
26: * custom feedback message filter, removes duplicates and works in conjunction
27: * with the ErrorHighlighter form component behavior
28: */
29: public class JtracFeedbackMessageFilter implements
30: IFeedbackMessageFilter {
31:
32: private Set<String> previous = new HashSet<String>();
33:
34: public void reset() {
35: previous.clear();
36: }
37:
38: public boolean accept(FeedbackMessage fm) {
39: String message = null;
40: // wicket bit too flexible, wicket internally created errors are not just Strings
41: // but if you added an error using the error(String) signature - will be just String
42: if (fm.getMessage() instanceof String) {
43: message = (String) fm.getMessage();
44: } else {
45: ValidationErrorFeedback error = (ValidationErrorFeedback) fm
46: .getMessage();
47: message = error.getMessage();
48: }
49: if (!previous.contains(message)) {
50: previous.add(message);
51: return true;
52: }
53: return false;
54: }
55:
56: }
|