1 16 package org.apache.cocoon.forms.formmodel; 17 18 import org.apache.cocoon.environment.Request; 19 import org.apache.cocoon.forms.FormContext; 20 import org.apache.cocoon.forms.event.*; 21 22 33 public class Action extends AbstractWidget implements ActionListenerEnabled { 34 35 private final ActionDefinition definition; 36 37 private ActionListener listener; 38 39 40 public Action(ActionDefinition definition) { 41 super(definition); 42 this.definition = definition; 43 } 44 45 public WidgetDefinition getDefinition() { 46 return this.definition; 47 } 48 49 public void readFromRequest(final FormContext formContext) { 50 if (!getCombinedState().isAcceptingInputs()) { 51 return; 52 } 53 54 Form form = getForm(); 55 56 String fullId = getRequestParameterName(); 58 Request request = formContext.getRequest(); 59 60 String value = request.getParameter(fullId); 61 if (value != null) { 62 form.setSubmitWidget(this); 63 64 } else { 65 value = request.getParameter(fullId + ".x"); 72 if ((value != null) && value.length() > 0) { 73 form.setSubmitWidget(this); 74 } 75 } 76 77 if (form.getSubmitWidget() == this) { 78 form.addWidgetEvent(new ActionEvent(this, definition.getActionCommand())); 79 handleActivate(); 80 } 81 } 82 83 88 protected void handleActivate() { 89 getForm().endProcessing(true); 90 } 91 92 97 public boolean validate() { 98 return true; 99 } 100 101 104 public boolean isValid() { 105 return true; 106 } 107 108 private static final String ACTION_EL = "action"; 109 110 113 public String getXMLElementName() { 114 return ACTION_EL; 115 } 116 117 122 public void addActionListener(ActionListener listener) { 123 this.listener = WidgetEventMulticaster.add(this.listener, listener); 124 } 125 126 public void removeActionListener(ActionListener listener) { 127 this.listener = WidgetEventMulticaster.remove(this.listener, listener); 128 } 129 130 private void fireActionEvent(ActionEvent event) { 131 if (this.listener != null) { 132 this.listener.actionPerformed(event); 133 } 134 } 135 136 public void broadcastEvent(WidgetEvent event) { 137 if (event instanceof ActionEvent) { 138 this.definition.fireActionEvent((ActionEvent)event); 139 fireActionEvent((ActionEvent)event); 140 } else { 141 super.broadcastEvent(event); 143 } 144 } 145 } 146 | Popular Tags |