1 16 package org.apache.cocoon.woody.formmodel; 17 18 import java.util.Iterator ; 19 20 import org.apache.cocoon.woody.Constants; 21 import org.apache.cocoon.woody.datatype.Datatype; 22 import org.apache.cocoon.woody.event.ValueChangedListener; 23 import org.apache.cocoon.woody.util.DomHelper; 24 import org.w3c.dom.Element ; 25 26 31 public class FieldDefinitionBuilder extends AbstractDatatypeWidgetDefinitionBuilder { 32 33 public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception { 34 FieldDefinition fieldDefinition = new FieldDefinition(); 35 buildWidgetDefinition(fieldDefinition, widgetElement); 36 return fieldDefinition; 37 } 38 39 protected void buildWidgetDefinition(FieldDefinition fieldDefinition, Element widgetElement) throws Exception { 40 setLocation(widgetElement, fieldDefinition); 41 setId(widgetElement, fieldDefinition); 42 43 Element datatypeElement = DomHelper.getChildElement(widgetElement, Constants.WD_NS, "datatype"); 44 if (datatypeElement == null) { 45 throw new Exception ("A nested datatype element is required for the widget at " + 46 DomHelper.getLocation(widgetElement)); 47 } 48 49 Datatype datatype = datatypeManager.createDatatype(datatypeElement, false); 50 fieldDefinition.setDatatype(datatype); 51 52 buildSelectionList(widgetElement, fieldDefinition); 53 54 Iterator iter = buildEventListeners(widgetElement, "on-value-changed", ValueChangedListener.class).iterator(); 55 while (iter.hasNext()) { 56 fieldDefinition.addValueChangedListener((ValueChangedListener)iter.next()); 57 } 58 59 setDisplayData(widgetElement, fieldDefinition); 60 setValidators(widgetElement, fieldDefinition); 61 62 boolean required = DomHelper.getAttributeAsBoolean(widgetElement, "required", false); 63 fieldDefinition.setRequired(required); 64 } 65 } 66 | Popular Tags |