1 20 package org.enhydra.barracuda.contrib.dbroggisch.examples.controller.handlers; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.http.HttpServletRequest ; 27 import org.enhydra.barracuda.core.event.ControlEventContext; 28 import org.enhydra.barracuda.core.event.EventException; 29 import org.enhydra.barracuda.core.forms.ValidationException; 30 import org.enhydra.barracuda.contrib.dbroggisch.page.Page; 31 import org.enhydra.barracuda.contrib.dbroggisch.page.PageEventListener; 32 import org.apache.log4j.Logger; 33 34 import org.enhydra.barracuda.contrib.dbroggisch.examples.controller.events.*; 35 import org.enhydra.barracuda.contrib.dbroggisch.examples.model.forms.*; 36 import org.enhydra.barracuda.contrib.dbroggisch.examples.view.pages.*; 37 38 39 public class PrefixMappingHandler extends PageEventListener { 40 41 private static final Logger logger = Logger.getLogger(PrefixMappingHandler.class.getName()); 42 43 public void handleControlEvent(ControlEventContext context, Page p) 44 throws EventException, ServletException , IOException { 45 HttpServletRequest request = context.getRequest(); 46 List maps = new ArrayList (); 47 ParentFormMap pfm = new ParentFormMap(); 48 PrefixmappingPage pmPage = (PrefixmappingPage)p; 49 pmPage.setState(ExampleBasePage.PREFIXMAPPING); 50 maps.add(pfm); 51 52 if (ParentFormMap.MODEL_NAME.equals(request.getParameter("visited"))) { 53 try { 54 pfm.map(request).validate(true); 55 } catch(ValidationException ex) { 56 logger.error("Form Validation Exception", ex); 57 } 58 59 int cc = (pfm.getVal(ParentFormMap.CHILD_COUNT) != null ? 60 ((Integer )pfm.getVal(ParentFormMap.CHILD_COUNT)).intValue() : 0); 61 62 if (context.getEvent() instanceof PrefixMappingAddChild) { 63 cc++; 64 pfm.getElement(ParentFormMap.CHILD_COUNT).setOrigVal("" + cc); 65 66 } 67 68 for (int i = 0; i < cc; i++) { 69 ChildFormMap cfm = new ChildFormMap(); 70 cfm.setPrefix("CFM" + i); 71 maps.add(cfm); 72 try { 73 cfm.map(request).validate(true); 74 } catch(ValidationException ex) { 75 logger.error("Form Validation Exception", ex); 76 } 77 } 78 } 79 pmPage.setMaps(maps); 80 context.getEvent().setHandled(true); 81 } 82 83 } 84 | Popular Tags |