1 15 package org.apache.tapestry.form; 16 17 import java.util.Collection ; 18 19 import org.apache.tapestry.IActionListener; 20 import org.apache.tapestry.IForm; 21 import org.apache.tapestry.IMarkupWriter; 22 import org.apache.tapestry.IRequestCycle; 23 import org.apache.tapestry.listener.ListenerInvoker; 24 25 31 32 abstract class AbstractSubmit extends AbstractFormComponent 33 { 34 41 protected abstract boolean isClicked(IRequestCycle cycle, String name); 42 43 46 protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle) 47 { 48 if (isClicked(cycle, getName())) 49 handleClick(cycle, getForm()); 50 } 51 52 void handleClick(final IRequestCycle cycle, IForm form) 53 { 54 if (isParameterBound("selected")) 55 setSelected(getTag()); 56 57 final IActionListener listener = getListener(); 58 59 if (listener == null) 60 return; 61 62 final ListenerInvoker listenerInvoker = getListenerInvoker(); 63 64 Object parameters = getParameters(); 65 if (parameters != null) 66 { 67 if (parameters instanceof Collection ) 68 { 69 cycle.setListenerParameters(((Collection ) parameters).toArray()); 70 } 71 else 72 { 73 cycle.setListenerParameters(new Object [] 74 { parameters }); 75 } 76 } 77 78 80 Runnable notify = new Runnable () 81 { 82 public void run() 83 { 84 listenerInvoker.invokeListener(listener, AbstractSubmit.this, cycle); 85 } 86 }; 87 88 if (getDefer()) 89 form.addDeferredRunnable(notify); 90 else 91 notify.run(); 92 } 93 94 95 public abstract IActionListener getListener(); 96 97 98 public abstract Object getTag(); 99 100 101 public abstract void setSelected(Object tag); 102 103 104 public abstract boolean getDefer(); 105 106 107 public abstract Object getParameters(); 108 109 110 public abstract ListenerInvoker getListenerInvoker(); 111 } 112 | Popular Tags |