KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > samples > flow > java > FormFlow


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