1 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 ; 29 import java.util.Date ; 30 31 38 public class InitForm1Action extends AbstractWoodyAction { 39 public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) 40 throws Exception { 41 String formSource = parameters.getParameter("form-definition"); 42 String 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 ()); 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 |