KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > 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.woody.samples;
17
18 import org.apache.cocoon.woody.acting.AbstractWoodyAction;
19 import org.apache.cocoon.woody.formmodel.Form;
20 import org.apache.cocoon.woody.formmodel.Repeater;
21 import org.apache.cocoon.woody.formmodel.Field;
22 import org.apache.cocoon.environment.Redirector;
23 import org.apache.cocoon.environment.SourceResolver;
24 import org.apache.cocoon.environment.Request;
25 import org.apache.cocoon.environment.ObjectModelHelper;
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 Woody,
33  * and adds some rows to its repeater widget. This example is meant to illustrate
34  * how you can prepopulate a Form instance before its initial display.
35  *
36  * @version $Id: InitForm1Action.java 30932 2004-07-29 17:35:38Z vgritsenko $
37  */

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