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.samples.flow.java;
18:
19: import java.util.Date;
20:
21: import org.apache.cocoon.components.flow.java.AbstractContinuable;
22: import org.apache.cocoon.components.flow.java.VarMap;
23: import org.apache.cocoon.forms.binding.BindingException;
24: import org.apache.cocoon.forms.flow.java.FormInstance;
25: import org.apache.cocoon.forms.formmodel.BooleanField;
26: import org.apache.cocoon.forms.formmodel.Field;
27: import org.apache.cocoon.forms.formmodel.Repeater;
28: import org.apache.cocoon.forms.samples.Contact;
29: import org.apache.cocoon.forms.samples.Form2Bean;
30: import org.apache.cocoon.forms.samples.Sex;
31:
32: public class FormFlow extends AbstractContinuable {
33:
34: public void doEditForm1() {
35:
36: FormInstance form = new FormInstance("forms/form1.xml");
37:
38: Field birthDate = (Field) form.getChild("birthdate");
39: birthDate.setValue(new Date());
40:
41: Repeater repeater = (Repeater) form.getChild("contacts");
42: repeater.addRow();
43: Field field = (Field) repeater.getWidget(0, "firstname");
44: field.setValue("Jules");
45:
46: repeater.addRow();
47: field = (Field) repeater.getWidget(1, "firstname");
48: field.setValue("Lucien");
49:
50: form.show("form/form1");
51:
52: sendPage("page/form1-result", new VarMap().add("email",
53: ((Field) form.getChild("email")).getValue()).add(
54: "somebool",
55: ((BooleanField) form.getChild("somebool")).getValue())
56: .add(
57: "firstname",
58: ((Field) ((Repeater) form.getChild("contacts"))
59: .getWidget(1, "firstname")).getValue()));
60: }
61:
62: public void doEditForm2() throws BindingException {
63: Form2Bean bean = new Form2Bean();
64:
65: // fill bean with some data to avoid users having to type to much
66: bean.setEmail("yourname@yourdomain.com");
67: bean.setIpAddress("10.0.0.1");
68: bean.setPhoneCountry("32");
69: bean.setPhoneZone("2");
70: bean.setPhoneNumber("123456");
71: bean.setBirthday(new java.util.Date());
72: bean.setSex(Sex.FEMALE);
73: Contact contact = new Contact();
74: contact.setId(1);
75: contact.setFirstName("Hermann");
76: bean.addContact(contact);
77:
78: FormInstance form = new FormInstance("forms/form2.xml",
79: "forms/form2-binding.xml");
80: form.load(bean);
81: form.show("form/form2");
82: form.save(bean);
83:
84: sendPage("page/form2-result", new VarMap().add("form2bean",
85: bean));
86: }
87: }
|