01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.woody.samples;
18:
19: import org.apache.cocoon.woody.acting.AbstractWoodyAction;
20: import org.apache.cocoon.woody.formmodel.Form;
21: import org.apache.cocoon.woody.formmodel.Repeater;
22: import org.apache.cocoon.woody.formmodel.Field;
23: import org.apache.cocoon.environment.Redirector;
24: import org.apache.cocoon.environment.SourceResolver;
25: import org.apache.cocoon.environment.Request;
26: import org.apache.cocoon.environment.ObjectModelHelper;
27: import org.apache.avalon.framework.parameters.Parameters;
28:
29: import java.util.Map;
30: import java.util.Date;
31:
32: /**
33: * An action that creates an instance of a specific example form included with Woody,
34: * and adds some rows to its repeater widget. This example is meant to illustrate
35: * how you can prepopulate a Form instance before its initial display.
36: *
37: * @version $Id: InitForm1Action.java 433543 2006-08-22 06:22:54Z crossley $
38: */
39: public class InitForm1Action extends AbstractWoodyAction {
40: public Map act(Redirector redirector, SourceResolver resolver,
41: Map objectModel, String source, Parameters parameters)
42: throws Exception {
43: String formSource = parameters.getParameter("form-definition");
44: String formAttribute = parameters
45: .getParameter("attribute-name");
46:
47: Form form = formManager.createForm(resolver
48: .resolveURI(formSource));
49:
50: Field birthDate = (Field) form.getWidget("birthdate");
51: birthDate.setValue(new Date());
52:
53: Repeater repeater = (Repeater) form.getWidget("contacts");
54: repeater.addRow();
55: Field field = (Field) repeater.getWidget(0, "firstname");
56: field.setValue("Jules");
57:
58: repeater.addRow();
59: field = (Field) repeater.getWidget(1, "firstname");
60: field.setValue("Lucien");
61:
62: Request request = ObjectModelHelper.getRequest(objectModel);
63: request.setAttribute(formAttribute, form);
64:
65: return null;
66: }
67: }
|