Author: nbelaevski
Date: 2011-01-19 14:46:27 -0500 (Wed, 19 Jan 2011)
New Revision: 21101
Added:
trunk/core/api/src/main/java/org/ajax4jsf/javascript/JSChainJSFFunction.java
Modified:
trunk/core/api/src/main/java/org/ajax4jsf/component/AjaxClientBehavior.java
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxFunction.java
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxOptions.java
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/util/AjaxRendererUtils.java
trunk/ui/core/ui/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
Log:
https://issues.jboss.org/browse/RF-7781
Modified: trunk/core/api/src/main/java/org/ajax4jsf/component/AjaxClientBehavior.java
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/component/AjaxClientBehavior.java 2011-01-19
18:42:01 UTC (rev 21100)
+++ trunk/core/api/src/main/java/org/ajax4jsf/component/AjaxClientBehavior.java 2011-01-19
19:46:27 UTC (rev 21101)
@@ -51,6 +51,10 @@
public void setOnbeforedomupdate(String onbeforedomupdate);
+ public String getOnbeforesubmit();
+
+ public void setOnbeforesubmit(String onbeforesubmit);
+
public Object getData();
public void setData(Object data);
Added: trunk/core/api/src/main/java/org/ajax4jsf/javascript/JSChainJSFFunction.java
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/javascript/JSChainJSFFunction.java
(rev 0)
+++
trunk/core/api/src/main/java/org/ajax4jsf/javascript/JSChainJSFFunction.java 2011-01-19
19:46:27 UTC (rev 21101)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.ajax4jsf.javascript;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class JSChainJSFFunction extends JSFunction {
+
+ private static Object[] createFunctionArgs(Object[] sourceParams) {
+ Object[] result = new Object[sourceParams.length + 2];
+
+ result[0] = JSReference.THIS;
+ result[1] = JSReference.EVENT;
+
+ for (int i = 0; i < sourceParams.length; i++) {
+ result[i + 2] = sourceParams[i];
+ }
+ return result;
+ }
+
+ public JSChainJSFFunction(Object... parameters) {
+ super("jsf.util.chain", (Object[]) createFunctionArgs(parameters));
+ }
+
+}
Modified: trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxFunction.java
===================================================================
--- trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxFunction.java 2011-01-19
18:42:01 UTC (rev 21100)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxFunction.java 2011-01-19
19:46:27 UTC (rev 21101)
@@ -23,6 +23,7 @@
import java.io.IOException;
+import org.ajax4jsf.javascript.JSChainJSFFunction;
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.javascript.ScriptStringBase;
import org.ajax4jsf.javascript.ScriptUtils;
@@ -71,7 +72,7 @@
this.options = eventOptions;
}
- public void appendScript(Appendable target) throws IOException {
+ private void appendAjaxFunctionCall(Appendable target) throws IOException {
target.append(FUNCTION_NAME);
target.append('(');
@@ -86,6 +87,17 @@
target.append(")");
}
+
+ public void appendScript(Appendable target) throws IOException {
+ if (options.getBeforesubmitHandler() == null) {
+ appendAjaxFunctionCall(target);
+ } else {
+ StringBuilder ajaxCall = new StringBuilder();
+ appendAjaxFunctionCall(ajaxCall);
+
+ ScriptUtils.appendScript(target, new
JSChainJSFFunction(options.getBeforesubmitHandler(), ajaxCall.toString()));
+ }
+ }
}
Modified: trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxOptions.java
===================================================================
--- trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxOptions.java 2011-01-19
18:42:01 UTC (rev 21100)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxOptions.java 2011-01-19
19:46:27 UTC (rev 21101)
@@ -41,6 +41,8 @@
private Map<String, Object> options = new HashMap<String, Object>();
+ private Object beforesubmitHandler;
+
public void appendScript(Appendable target) throws IOException {
ScriptUtils.appendScript(target, options);
}
@@ -125,4 +127,12 @@
public void setAjaxComponent(Object ajaxComponent) {
getParameters().put(AjaxConstants.AJAX_COMPONENT_ID_PARAMETER, ajaxComponent);
}
+
+ public Object getBeforesubmitHandler() {
+ return beforesubmitHandler;
+ }
+
+ public void setBeforesubmitHandler(Object beforesubmitHandler) {
+ this.beforesubmitHandler = beforesubmitHandler;
+ }
}
Modified:
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/util/AjaxRendererUtils.java
===================================================================
---
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/util/AjaxRendererUtils.java 2011-01-19
18:42:01 UTC (rev 21100)
+++
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/util/AjaxRendererUtils.java 2011-01-19
19:46:27 UTC (rev 21101)
@@ -43,6 +43,7 @@
*/
public final class AjaxRendererUtils {
+ public static final String BEGIN_EVENT_NAME = "begin";
public static final String AJAX_ABORT_ATTR = "ignoreDupResponses";
public static final String AJAX_AREAS_RENDERED =
"org.ajax4jsf.areas.rendered";
public static final String AJAX_DELAY_ATTR = "requestDelay";
@@ -231,6 +232,7 @@
private static void appenAjaxBehaviorOptions(ClientBehaviorContext behaviorContext,
AjaxClientBehavior behavior, AjaxOptions ajaxOptions) {
ajaxOptions.setParameter(AjaxConstants.BEHAVIOR_EVENT_PARAMETER,
behaviorContext.getEventName());
+ ajaxOptions.setBeforesubmitHandler(behavior.getOnbeforesubmit());
for (BehaviorOptionsData optionsData : BehaviorOptionsData.values()) {
String optionValue = optionsData.getAttributeValue(behavior);
@@ -240,20 +242,22 @@
}
}
}
-
- private static void appendComponentOptions(FacesContext facesContext, UIComponent
component,
- AjaxOptions ajaxOptions) {
- String behaviorName = "begin";
+
+ private static String getHandlerScript(FacesContext facesContext, UIComponent
component, String attributeName, String eventName) {
HandlersChain handlersChain = new HandlersChain(facesContext, component);
- String inlineHandler = getAjaxOnBegin(component);
+ String inlineHandler = (String) component.getAttributes().get(attributeName);
handlersChain.addInlineHandlerAsValue(inlineHandler);
- handlersChain.addBehaviors(behaviorName);
+ handlersChain.addBehaviors(eventName);
- String handlerScript = handlersChain.toScript();
+ return handlersChain.toScript();
+ }
+ private static void appendComponentOptions(FacesContext facesContext, UIComponent
component,
+ AjaxOptions ajaxOptions) {
+ String handlerScript = getHandlerScript(facesContext, component,
ONBEGIN_ATTR_NAME, BEGIN_EVENT_NAME);
if (isNotEmpty(handlerScript)) {
- ajaxOptions.set(behaviorName, handlerScript);
+ ajaxOptions.set(BEGIN_EVENT_NAME, handlerScript);
}
String queueId = getQueueId(component);
@@ -585,9 +589,4 @@
return function;
}
- //TODO nick - refactor - remove this method?
- public static String getAjaxOnBegin(UIComponent component) {
- return (String) component.getAttributes().get(ONBEGIN_ATTR_NAME);
- }
-
}
Modified:
trunk/ui/core/ui/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
===================================================================
---
trunk/ui/core/ui/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2011-01-19
18:42:01 UTC (rev 21100)
+++
trunk/ui/core/ui/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2011-01-19
19:46:27 UTC (rev 21101)
@@ -22,12 +22,6 @@
package org.ajax4jsf.component.behavior;
-import static org.richfaces.renderkit.AjaxConstants.ALL;
-import static org.richfaces.renderkit.AjaxConstants.FORM;
-import static org.richfaces.renderkit.AjaxConstants.NONE;
-import static org.richfaces.renderkit.AjaxConstants.REGION;
-import static org.richfaces.renderkit.AjaxConstants.THIS;
-
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
@@ -67,15 +61,9 @@
private static final Set<ClientBehaviorHint> HINTS =
Collections.unmodifiableSet(EnumSet
.of(ClientBehaviorHint.SUBMITTING));
- private static final Set<String> ALL_SINGLETON_SET =
Collections.singleton(ALL);
- private static final Set<String> FORM_SINGLETON_SET =
Collections.singleton(FORM);
- private static final Set<String> THIS_SINGLETON_SET =
Collections.singleton(THIS);
- private static final Set<String> REGION_SINGLETON_SET =
Collections.singleton(REGION);
- private static final Set<String> NONE_SINGLETON_SET =
Collections.singleton(NONE);
-
enum PropertyKeys {
data, execute, onbeforedomupdate, onbegin, oncomplete, onerror, queueId, render,
- status, disabled, limitRender, immediate, bypassUpdates
+ status, disabled, limitRender, immediate, bypassUpdates, onbeforesubmit
}
private Set<String> execute;
@@ -121,6 +109,8 @@
} else if (compare(PropertyKeys.bypassUpdates, name)) {
value = expFactory.coerceToType(value, Boolean.class);
setBypassUpdates((Boolean) value);
+ } else if (compare(PropertyKeys.onbeforesubmit, name)) {
+ setOnbeforesubmit((String) value);
}
}
@@ -139,36 +129,6 @@
return result;
}
- private Set<String> toSingletonSet(String propertyName, String value) {
-
- if(value == null) {
- return null;
- }
-
- if(value.trim().length() == 0) {
- return null;
- }
-
- if(value.charAt(0) == '@') {
- if (ALL.equals(value)) {
- return ALL_SINGLETON_SET;
- } else if (FORM.equals(value)) {
- return FORM_SINGLETON_SET;
- } else if (THIS.equals(value)) {
- return THIS_SINGLETON_SET;
- } else if (REGION.equals(value)) {
- return REGION_SINGLETON_SET;
- } else if (NONE.equals(value)) {
- return NONE_SINGLETON_SET;
- } else {
- throw new FacesException(value + " : Invalid id keyword specified
for '"
- + propertyName + "' attribute");
- }
- }
-
- return null;
- }
-
@Attribute
public Object getData() {
return getStateHelper().eval(PropertyKeys.data);
@@ -207,6 +167,15 @@
}
@Attribute
+ public String getOnbeforesubmit() {
+ return (String) getStateHelper().eval(PropertyKeys.onbeforesubmit);
+ }
+
+ public void setOnbeforesubmit(String onbeforesubmit) {
+ getStateHelper().put(PropertyKeys.onbeforesubmit, onbeforesubmit);
+ }
+
+ @Attribute
public String getOncomplete() {
return (String) getStateHelper().eval(PropertyKeys.oncomplete);
}