You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2007/03/12 10:15:15 UTC
svn commit: r517140 - in /myfaces/tobago/trunk:
core/src/main/java/org/apache/myfaces/tobago/taglib/component/
theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/
theme/standard/src/main/resources/org/apac...
Author: weber
Date: Mon Mar 12 02:15:13 2007
New Revision: 517140
URL: http://svn.apache.org/viewvc?view=rev&rev=517140
Log:
TOBAGO-311 (Onsubmit javascript hookin ability)
enable interrupting of submit by returning false
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ScriptTag.java
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java
myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ScriptTag.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ScriptTag.java?view=diff&rev=517140&r1=517139&r2=517140
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ScriptTag.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ScriptTag.java Mon Mar 12 02:15:13 2007
@@ -141,6 +141,8 @@
/**
* A script function which is invoked on client just before submitting the action.
+ * This should be a single function call. If the result is typeof 'boolean' and false
+ * the further processing is canceled and the page is not submitted.
*/
@TagAttribute
public void setOnsubmit(String onsubmit) {
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java?view=diff&rev=517140&r1=517139&r2=517140
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java Mon Mar 12 02:15:13 2007
@@ -264,15 +264,15 @@
}
//page.getOnloadScripts()
// onload script
- writeEventFunction(writer, page.getOnloadScripts(), "load");
+ writeEventFunction(writer, page.getOnloadScripts(), "load", false);
// onunload script
- writeEventFunction(writer, page.getOnunloadScripts(), "unload");
+ writeEventFunction(writer, page.getOnunloadScripts(), "unload", false);
// onexit script
- writeEventFunction(writer, page.getOnexitScripts(), "exit");
+ writeEventFunction(writer, page.getOnexitScripts(), "exit", false);
- writeEventFunction(writer, page.getOnsubmitScripts(), "submit");
+ writeEventFunction(writer, page.getOnsubmitScripts(), "submit", true);
int debugCounter = 0;
for (String script : page.getScriptBlocks()) {
@@ -423,19 +423,32 @@
}
private void writeEventFunction(
- TobagoResponseWriter writer, Set<String> eventFunctions, String event)
+ TobagoResponseWriter writer, Set<String> eventFunctions, String event, boolean returnBoolean)
throws IOException {
if (!eventFunctions.isEmpty()) {
- writer.write("Tobago.applicationOn" + event + " = function() {\n ");
+ writer.write("Tobago.applicationOn" + event + " = function() {\n");
+ if (returnBoolean) {
+ writer.write(" var result;\n");
+ }
for (String function : eventFunctions) {
+ if (returnBoolean) {
+ writer.write(" result = ");
+ } else {
+ writer.write(" ");
+ }
writer.write(function);
if (!function.trim().endsWith(";")) {
- writer.write(";\n ");
+ writer.write(";\n");
} else {
- writer.write("\n ");
+ writer.write("\n");
+ }
+ if (returnBoolean) {
+ writer.write(" if (typeof result == \"boolean\" && ! result) {\n");
+ writer.write(" return false;\n");
+ writer.write(" }\n");
}
}
- writer.write("\n}\n");
+ writer.write("\n return true;\n}\n");
}
}
Modified: myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?view=diff&rev=517140&r1=517139&r2=517140
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Mon Mar 12 02:15:13 2007
@@ -428,7 +428,12 @@
Tobago.form.target = target;
}
if (Tobago.applicationOnsubmit) {
- Tobago.applicationOnsubmit();
+ if (!Tobago.applicationOnsubmit()) {
+ this.isSubmit = false;
+ Tobago.action.value = oldAction;
+ Tobago.form.target = oldTarget;
+ return;
+ }
}
Tobago.onSubmit();
// LOG.debug("submit form with action: " + Tobago.action.value);
@@ -1722,15 +1727,18 @@
update: function(container, page, actionId, ajaxComponentId, options) {
if (this.hasTransport()) {
+
+ if (Tobago.applicationOnsubmit) {
+ if (!Tobago.applicationOnsubmit()) {
+ return;
+ }
+ }
+
var requestOptions = Tobago.extend({}, this.options);
if (options) {
Tobago.extend(requestOptions, options);
}
- if (Tobago.applicationOnsubmit) {
- Tobago.applicationOnsubmit();
- }
-
if (requestOptions.createOverlay) {
Tobago.createOverlay(container);
}