You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2006/07/02 22:56:19 UTC
svn commit: r418648 - in /tapestry/tapestry4/trunk:
examples/TimeTracker/src/context/
framework/src/java/org/apache/tapestry/form/
framework/src/java/org/apache/tapestry/services/impl/
framework/src/js/tapestry/
Author: jkuhnert
Date: Sun Jul 2 13:56:18 2006
New Revision: 418648
URL: http://svn.apache.org/viewvc?rev=418648&view=rev
Log:
Added evaluation of js during ajax responses.
Modified:
tapestry/tapestry4/trunk/examples/TimeTracker/src/context/Home.html
tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContextImpl.java
tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormSupportImpl.java
tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/DojoAjaxResponseBuilder.java
tapestry/tapestry4/trunk/framework/src/js/tapestry/core.js
tapestry/tapestry4/trunk/framework/src/js/tapestry/form.js
Modified: tapestry/tapestry4/trunk/examples/TimeTracker/src/context/Home.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/examples/TimeTracker/src/context/Home.html?rev=418648&r1=418647&r2=418648&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/examples/TimeTracker/src/context/Home.html (original)
+++ tapestry/tapestry4/trunk/examples/TimeTracker/src/context/Home.html Sun Jul 2 13:56:18 2006
@@ -53,7 +53,7 @@
<span jwcid="@If" condition="ognl:selectedProject">
<label jwcid="@FieldLabel" field="component:feedbackField" />
<input jwcid="feedbackField@TextField" displayName="message:feedback"
- value="ognl:feedback" />
+ value="ognl:feedback" validators="validators:required,minLength=6" />
</span>
</div>
Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContextImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContextImpl.java?rev=418648&r1=418647&r2=418648&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContextImpl.java (original)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormComponentContributorContextImpl.java Sun Jul 2 13:56:18 2006
@@ -89,7 +89,7 @@
public void addInitializationScript(IComponent target, String script)
{
- _pageRenderSupport.addInitializationScript(target, script);
+ _pageRenderSupport.addInitializationScript(_form, script);
}
public void registerForFocus(int priority)
Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormSupportImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormSupportImpl.java?rev=418648&r1=418647&r2=418648&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormSupportImpl.java (original)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/form/FormSupportImpl.java Sun Jul 2 13:56:18 2006
@@ -521,7 +521,7 @@
writeHiddenFields();
// Close the nested writer, inserting its contents.
-
+
nested.close();
// Close the <form> tag.
@@ -545,7 +545,8 @@
// register the validation profile with client side form manager
if (_form.isClientValidationEnabled()) {
- _pageRenderSupport.addInitializationScript(_form, "tapestry.form.registerProfile('" + formId + "',"
+ _pageRenderSupport.addInitializationScript(_form, "tapestry.form.clearProfiles('"
+ + formId + "'); tapestry.form.registerProfile('" + formId + "',"
+ _profile.toString() + ");");
}
}
Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/DojoAjaxResponseBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/DojoAjaxResponseBuilder.java?rev=418648&r1=418647&r2=418648&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/DojoAjaxResponseBuilder.java (original)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/DojoAjaxResponseBuilder.java Sun Jul 2 13:56:18 2006
@@ -23,6 +23,7 @@
import org.apache.hivemind.util.Defense;
import org.apache.tapestry.IComponent;
+import org.apache.tapestry.IForm;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRender;
@@ -163,6 +164,11 @@
*/
public boolean isBodyScriptAllowed(IComponent target)
{
+ if (target != null
+ && IForm.class.isInstance(target)
+ && ((IForm)target).isFormFieldUpdating())
+ return true;
+
return contains(target);
}
@@ -171,6 +177,11 @@
*/
public boolean isExternalScriptAllowed(IComponent target)
{
+ if (target != null
+ && IForm.class.isInstance(target)
+ && ((IForm)target).isFormFieldUpdating())
+ return true;
+
return contains(target);
}
@@ -179,6 +190,11 @@
*/
public boolean isInitializationScriptAllowed(IComponent target)
{
+ if (target != null
+ && IForm.class.isInstance(target)
+ && ((IForm)target).isFormFieldUpdating())
+ return true;
+
return contains(target);
}
Modified: tapestry/tapestry4/trunk/framework/src/js/tapestry/core.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/tapestry/core.js?rev=418648&r1=418647&r2=418648&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/js/tapestry/core.js (original)
+++ tapestry/tapestry4/trunk/framework/src/js/tapestry/core.js Sun Jul 2 13:56:18 2006
@@ -12,6 +12,8 @@
tapestry={
version:"4.1",
+ scriptInFlight:false,
+ ScriptFragment:'(?:<script.*?>)((\n|.|\r)*?)(?:<\/script>)',
/**
* Global XHR bind function for tapestry internals. The
@@ -58,6 +60,7 @@
}
var elms=resp[0].childNodes;
+ var scripts=[];
for (var i=0; i<elms.length; i++) {
var type=elms[i].getAttribute("type");
var id=elms[i].getAttribute("id");
@@ -68,6 +71,11 @@
return;
}
+ if (type == "script") {
+ scripts.push(elms[i]);
+ continue;
+ }
+
if (!id) {
dojo.raise("No element id found in ajax-response node.");
return;
@@ -81,6 +89,10 @@
tapestry.loadContent(id, node, elms[i]);
}
+
+ for (var i=0; i<scripts.length; i++) {
+ tapestry.loadScriptContent(scripts[i], true);
+ }
},
loadContent:function(id, node, element){
@@ -97,6 +109,59 @@
}
node.innerHTML=tapestry.html.getContentAsString(element);
+ },
+
+ loadScriptContent:function(element, async){
+ if (typeof async == "undefined") async = true;
+
+ var text=tapestry.html.getContentAsString(element);
+
+ if (tapestry.scriptInFlight) {
+ dojo.log.debug("loadScriptContent(): scriptInFlight is true, sleeping");
+ setTimeout(function() { tapestry.loadScriptContent(text, async);}, 5);
+ return;
+ }
+
+ var match = new RegExp(tapestry.ScriptFragment, 'img');
+ var response = text.replace(match, '');
+ var scripts = text.match(match);
+
+ if (!scripts) return;
+
+ match = new RegExp(tapestry.ScriptFragment, 'im');
+ if (async) {
+ setTimeout(function() {
+ tapestry.scriptInFlight = true;
+
+ for (var i=0; i<scripts.length; i++) {
+ var scr = scripts[i].match(match)[1];
+ try {
+ dojo.log.debug("evaluating script:" + scr);
+ eval(scr);
+ } catch (e) {
+ tapestry.scriptInFlight = false;
+ dojo.log.exception("Error evaluating script: " + scr, e, false);
+ }
+ }
+
+ tapestry.scriptInFlight = false;
+ }, 60);
+ } else {
+ tapestry.scriptInFlight = true;
+
+ for (var i=0; i<scripts.length; i++) {
+ var scr = scripts[i].match(match)[1];
+ try {
+ dojo.log.debug("synchronous eval of script:" + scr);
+ eval(scr);
+ } catch (e) {
+ tapestry.scriptInFlight = false;
+ dojo.log.exception("Error synchronously evaluating script: " + scr, e, false);
+ }
+ }
+
+ tapestry.scriptInFlight = false;
+ }
},
presentException:function(node, kwArgs) {
Modified: tapestry/tapestry4/trunk/framework/src/js/tapestry/form.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/js/tapestry/form.js?rev=418648&r1=418647&r2=418648&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/js/tapestry/form.js (original)
+++ tapestry/tapestry4/trunk/framework/src/js/tapestry/form.js Sun Jul 2 13:56:18 2006
@@ -152,6 +152,23 @@
},
/**
+ * Clears any previously registered validation profiles
+ * on the specified form. Normally called during XHR requests
+ * by returned JS response to ensure new validation logic coming
+ * in from potentially new form fields is accounted for.
+ *
+ * @param id The form id to clear profiles for.
+ */
+ clearProfiles:function(id){
+ if (!this.forms[id]) return;
+
+ for (var i=0; i < this.forms[id].profiles.length; i++) {
+ delete this.forms[id].profiles[i];
+ }
+ this.forms[id].profiles=[];
+ },
+
+ /**
* If a form registered with the specified formId
* exists a local property will be set that causes
* validation to be turned on/off depending on the argument.