KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > contrib > dbroggisch > examples > controller > handlers > PrefixMappingHandler


1 /*
2  * Copyright (C) 2003 Diez B. Roggisch [deets@web.de]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: PrefixMappingHandler.java,v 1.2 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.contrib.dbroggisch.examples.controller.handlers;
21
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.servlet.ServletException JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
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 JavaDoc, IOException JavaDoc {
45         HttpServletRequest JavaDoc request = context.getRequest();
46         List JavaDoc maps = new ArrayList JavaDoc();
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 JavaDoc)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