1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.util;
17
18 import java.util.HashMap;
19 import java.util.HashSet;
20 import java.util.Iterator;
21
22 import org.apache.struts.action.ActionErrors;
23 import org.apache.struts.action.ActionMessage;
24 import org.apache.struts.action.ActionMessages;
25
26 /***
27 * 同じメッセージが複数登録されるのを防ぐActionErrors
28 *
29 * @author hatanaka
30 */
31 public class ActionErrorsSet extends ActionErrors {
32 private static final long serialVersionUID = 1L;
33
34 private HashMap errorsMap=new HashMap();
35
36 public void add(String key, ActionMessage message) {
37 if(!errorsMap.containsKey(key)){
38 errorsMap.put(key, new HashSet());
39 }
40 HashSet errorsSet=(HashSet)errorsMap.get(key);
41 if(!errorsSet.contains(message.toString())){
42 errorsSet.add(message.toString());
43 super.add(key, message);
44 }
45 }
46
47 public void add(ActionMessages messages) {
48 for(Iterator props=messages.properties(); props.hasNext();){
49 String key=(String)props.next();
50 for(Iterator msgs=messages.get(key); msgs.hasNext();){
51 ActionMessage message=(ActionMessage)msgs.next();
52 add(key, message);
53 }
54 }
55 }
56 }