1 16 package org.apache.cocoon.samples.flow.java; 17 18 import java.util.Date ; 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 ()); 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 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 ()); 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 |