1 16 package org.apache.cocoon.forms.formmodel; 17 18 import org.apache.cocoon.forms.FormContext; 19 20 27 public class RepeaterAction extends Action { 28 29 private Repeater repeater; 30 31 32 public RepeaterAction(RepeaterActionDefinition definition) { 33 super(definition); 34 } 35 36 39 public Repeater getRepeater() { 40 if (this.repeater == null) { 41 String name = ((RepeaterActionDefinition)getDefinition()).getRepeaterName(); 42 Widget widget; 43 if (name != null) { 44 widget = ((ContainerWidget)getParent()).getChild(name); 46 } else { 47 widget = getParent().getParent(); 49 } 50 51 if (widget == null || !(widget instanceof Repeater)) { 52 throw new RuntimeException (name != null ? 53 "Cannot find sibling repeater named '" + name + "'." : 54 "Parent widget is not a repeater"); 55 } 56 57 this.repeater = (Repeater)widget; 58 } 59 60 return this.repeater; 61 } 62 63 public static class Move extends RepeaterAction { 64 private int from; 65 private int to; 66 67 public Move(RepeaterActionDefinition definition) { 68 super(definition); 69 } 70 71 public void readFromRequest(FormContext formContext) { 72 String fullName = getFullName(); 73 String fromStr = formContext.getRequest().getParameter(fullName + ".from"); 74 if (fromStr != null) { 75 from = Integer.parseInt(fromStr); 76 to = Integer.parseInt(formContext.getRequest().getParameter(fullName + ".to")); 77 } else { 78 from = -1; 79 to = -1; 80 } 81 super.readFromRequest(formContext); 82 } 83 84 public int getFrom() { 85 return from; 86 } 87 88 public int getTo() { 89 return to; 90 } 91 }; 92 } 93 | Popular Tags |