1 16 package org.apache.cocoon.woody.formmodel; 17 18 import java.util.Iterator ; 19 20 import org.apache.cocoon.woody.event.ActionListener; 21 import org.apache.cocoon.woody.util.DomHelper; 22 import org.w3c.dom.Element ; 23 24 40 public class RepeaterActionDefinitionBuilder extends AbstractWidgetDefinitionBuilder { 41 42 43 public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception { 44 String actionCommand = DomHelper.getAttribute(widgetElement, "action-command"); 45 RepeaterActionDefinition definition = createDefinition(widgetElement, actionCommand); 46 setLocation(widgetElement, definition); 47 setId(widgetElement, definition); 48 setDisplayData(widgetElement, definition); 49 setValidators(widgetElement, definition); 50 51 definition.setActionCommand(actionCommand); 52 53 Iterator iter = buildEventListeners(widgetElement, "on-activate", ActionListener.class).iterator(); 54 while (iter.hasNext()) { 55 definition.addActionListener((ActionListener)iter.next()); 56 } 57 58 return definition; 59 } 60 61 protected RepeaterActionDefinition createDefinition(Element element, String actionCommand) throws Exception { 62 63 if ("delete-rows".equals(actionCommand)) { 64 String repeater = DomHelper.getAttribute(element, "repeater"); 65 String select = DomHelper.getAttribute(element, "select"); 66 return new DeleteRowsActionDefinition(repeater, select); 67 68 } else if ("add-row".equals(actionCommand)) { 69 String repeater = DomHelper.getAttribute(element, "repeater"); 70 return new AddRowActionDefinition(repeater); 71 72 } else { 73 throw new Exception ("Unknown repeater action '" + actionCommand + "' at " + DomHelper.getLineLocation(element)); 74 } 75 } 76 } 77 | Popular Tags |