1 20 package org.enhydra.barracuda.contrib.dbroggisch.repopulation; 21 22 import org.enhydra.barracuda.core.comp.*; 23 import org.enhydra.barracuda.core.forms.*; 24 import org.enhydra.barracuda.core.forms.validators.*; 25 import org.enhydra.barracuda.core.comp.model.*; 26 import org.apache.log4j.*; 27 import java.util.*; 28 29 46 public class ErrorFormMap extends DefaultFormMap 47 { 48 private Map errorMap = new HashMap(); 49 public static String ERROR_PREFIX = "e_"; 50 protected static final Logger logger = Logger.getLogger(ErrorFormMap.class.getName()); 51 52 53 public FormMap validate(boolean deferExceptions) throws ValidationException { 54 errorMap.clear(); 55 try { 56 super.validate(deferExceptions); 57 } 58 catch(ValidationException ex) { 59 if(logger.isDebugEnabled()) { 60 logger.debug("Catched ValidationException"); 61 } 62 List e_list; 63 if(deferExceptions) { 64 e_list = ex.getExceptionList(); 65 } 66 else { 67 e_list = new Vector(); 68 e_list.add(ex); 69 } 70 71 for(int i = 0; i < e_list.size(); i++) { 72 if(logger.isDebugEnabled()) { 73 logger.debug("Visiting Exception " + i); 74 } 75 ValidationException vex = (ValidationException)e_list.get(i); 76 if(vex.getSource() instanceof FormElement) { 77 FormElement fel = (FormElement)vex.getSource(); 78 BComponent comp; 79 80 logger.debug("Element name: " + fel.getName()); 81 if(vex.getMessage() != null && !vex.getMessage().equals("")) { 82 if(logger.isDebugEnabled()) { 83 logger.debug("Adding BText with " + vex.getMessage()); 84 } 85 comp = new BText(); 86 ((BText)comp).setText(vex.getMessage()); 87 } 88 else { 89 if(logger.isDebugEnabled()) { 90 logger.debug("Adding BComponent"); 91 } 92 comp = new BComponent(); 93 } 94 errorMap.put(ERROR_PREFIX + fel.getKey(), comp); 95 } 96 } 97 throw ex; 98 } 99 return this; 100 } 101 102 103 106 public void addErrorComponent(String key, BComponent comp) { 107 errorMap.put(key, comp); 108 } 109 110 112 public Object getErrorComponent(String key) 113 { 114 if(errorMap.containsKey(key)){ 115 return errorMap.get(key); 116 } 117 return null; 118 } 119 } 120 | Popular Tags |