1 16 package org.apache.cocoon.forms.samples; 17 18 import org.apache.cocoon.environment.Redirector; 19 import org.apache.cocoon.environment.SourceResolver; 20 import org.apache.cocoon.environment.Request; 21 import org.apache.cocoon.environment.ObjectModelHelper; 22 import org.apache.cocoon.forms.acting.AbstractFormsAction; 23 import org.apache.cocoon.forms.formmodel.Field; 24 import org.apache.cocoon.forms.formmodel.Form; 25 import org.apache.cocoon.forms.formmodel.Repeater; 26 import org.apache.avalon.framework.parameters.Parameters; 27 28 import java.util.Map ; 29 import java.util.Date ; 30 31 39 public class InitForm1Action extends AbstractFormsAction { 40 public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) 41 throws Exception { 42 String formSource = parameters.getParameter("form-definition"); 43 String formAttribute = parameters.getParameter("attribute-name"); 44 45 Form form = formManager.createForm(resolver.resolveURI(formSource)); 46 47 Field birthDate = (Field)form.getChild("birthdate"); 48 birthDate.setValue(new Date ()); 49 50 Repeater repeater = (Repeater)form.getChild("contacts"); 51 repeater.addRow(); 52 Field field = (Field)repeater.getWidget(0, "firstname"); 53 field.setValue("Jules"); 54 55 repeater.addRow(); 56 field = (Field)repeater.getWidget(1, "firstname"); 57 field.setValue("Lucien"); 58 59 Request request = ObjectModelHelper.getRequest(objectModel); 60 request.setAttribute(formAttribute, form); 61 62 return null; 63 } 64 } 65 | Popular Tags |