KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > samples > InitForm1Action


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 package org.apache.cocoon.forms.samples;
17
18 import org.apache.cocoon.environment.Redirector;
19 import org.apache.cocoon.environment.SourceResolver;
20 import org.apache.cocoon.environment.Request;
21 import org.apache.cocoon.environment.ObjectModelHelper;
22 import org.apache.cocoon.forms.acting.AbstractFormsAction;
23 import org.apache.cocoon.forms.formmodel.Field;
24 import org.apache.cocoon.forms.formmodel.Form;
25 import org.apache.cocoon.forms.formmodel.Repeater;
26 import org.apache.avalon.framework.parameters.Parameters;
27
28 import java.util.Map JavaDoc;
29 import java.util.Date JavaDoc;
30
31 /**
32  * An action that creates an instance of a specific example form included with
33  * Cocoon Forms, and adds some rows to its repeater widget. This example is
34  * meant to illustrate how you can prepopulate a Form instance before its
35  * initial display.
36  *
37  * @version $Id: InitForm1Action.java 56582 2004-11-04 10:16:22Z sylvain $
38  */

39 public class InitForm1Action extends AbstractFormsAction {
40     public Map JavaDoc act(Redirector redirector, SourceResolver resolver, Map JavaDoc objectModel, String JavaDoc source, Parameters parameters)
41             throws Exception JavaDoc {
42         String JavaDoc formSource = parameters.getParameter("form-definition");
43         String JavaDoc formAttribute = parameters.getParameter("attribute-name");
44
45         Form form = formManager.createForm(resolver.resolveURI(formSource));
46
47         Field birthDate = (Field)form.getChild("birthdate");
48         birthDate.setValue(new Date JavaDoc());
49
50         Repeater repeater = (Repeater)form.getChild("contacts");
51         repeater.addRow();
52         Field field = (Field)repeater.getWidget(0, "firstname");
53         field.setValue("Jules");
54
55         repeater.addRow();
56         field = (Field)repeater.getWidget(1, "firstname");
57         field.setValue("Lucien");
58
59         Request request = ObjectModelHelper.getRequest(objectModel);
60         request.setAttribute(formAttribute, form);
61
62         return null;
63     }
64 }
65
Popular Tags