You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2008/09/10 20:09:37 UTC
svn commit: r693917 - in /tapestry/tapestry5/trunk:
tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/
tapestry-upload/src/main/java/org/apache/tapestry5/upload/components/
tapestry-upload/src/main/resources/org/apache/tapestry5/uploa...
Author: hlship
Date: Wed Sep 10 11:09:35 2008
New Revision: 693917
URL: http://svn.apache.org/viewvc?rev=693917&view=rev
Log:
TAPESTRY-2453: Form enctype is not updated when an Upload component is injected via FormInjector / AjaxFormLoop
Added:
tapestry/tapestry5/trunk/tapestry-upload/src/main/resources/org/apache/tapestry5/upload/components/
tapestry/tapestry5/trunk/tapestry-upload/src/main/resources/org/apache/tapestry5/upload/components/upload.js
tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/example/upload/pages/Ajaxified.java
tapestry/tapestry5/trunk/tapestry-upload/src/test/webapp/Ajaxified.tml
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java
tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry5/upload/components/Upload.java
tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/example/upload/services/AppModule.java
tapestry/tapestry5/trunk/tapestry-upload/src/test/webapp/Start.tml
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java?rev=693917&r1=693916&r2=693917&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java Wed Sep 10 11:09:35 2008
@@ -88,6 +88,9 @@
@Environmental
private ClientBehaviorSupport clientBehaviorSupport;
+ @Environmental
+ private Heartbeat heartbeat;
+
@Inject
@Ajax
private ComponentEventResultProcessor componentEventResultProcessor;
@@ -217,10 +220,14 @@
environment.push(FormSupport.class, formSupport);
environment.push(ValidationTracker.class, new ValidationTrackerImpl());
+ heartbeat.begin();
+
renderer.renderMarkup(writer, reply);
formSupport.executeDeferred();
+ heartbeat.end();
+
environment.pop(ValidationTracker.class);
environment.pop(FormSupport.class);
Modified: tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry5/upload/components/Upload.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry5/upload/components/Upload.java?rev=693917&r1=693916&r2=693917&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry5/upload/components/Upload.java (original)
+++ tapestry/tapestry5/trunk/tapestry-upload/src/main/java/org/apache/tapestry5/upload/components/Upload.java Wed Sep 10 11:09:35 2008
@@ -18,12 +18,14 @@
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.Mixin;
import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.Path;
import org.apache.tapestry5.corelib.base.AbstractField;
import org.apache.tapestry5.corelib.mixins.RenderDisabled;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.ComponentDefaultProvider;
import org.apache.tapestry5.services.FieldValidatorDefaultSource;
import org.apache.tapestry5.services.FormSupport;
+import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.upload.services.MultipartDecoder;
import org.apache.tapestry5.upload.services.UploadedFile;
@@ -77,6 +79,16 @@
@Mixin
private RenderDisabled renderDisabled;
+ @Inject
+ @Path("upload.js")
+ private Asset uploadScript;
+
+ @Inject
+ private Request request;
+
+ @Environmental
+ private RenderSupport renderSupport;
+
/**
* Computes a default value for the "validate" parameter using {@link FieldValidatorDefaultSource}.
*/
@@ -140,6 +152,13 @@
resources.renderInformalParameters(writer);
decorateInsideField();
+
+ // TAPESTRY-2453
+ if (request.isXHR())
+ {
+ renderSupport.addScriptLink(uploadScript);
+ renderSupport.addInit("injectedUpload", getClientId());
+ }
}
public void afterRender(MarkupWriter writer)
Added: tapestry/tapestry5/trunk/tapestry-upload/src/main/resources/org/apache/tapestry5/upload/components/upload.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-upload/src/main/resources/org/apache/tapestry5/upload/components/upload.js?rev=693917&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-upload/src/main/resources/org/apache/tapestry5/upload/components/upload.js (added)
+++ tapestry/tapestry5/trunk/tapestry-upload/src/main/resources/org/apache/tapestry5/upload/components/upload.js Wed Sep 10 11:09:35 2008
@@ -0,0 +1,22 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/**
+ * Ensures that the encoding type of the containing form is multipart/form-data when an Upload
+ * component is dynamically added to the form via Ajax.
+ */
+Tapestry.Initializer.injectedUpload = function(element)
+{
+ $(element).form.enctype = "multipart/form-data";
+}
\ No newline at end of file
Added: tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/example/upload/pages/Ajaxified.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/example/upload/pages/Ajaxified.java?rev=693917&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/example/upload/pages/Ajaxified.java (added)
+++ tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/example/upload/pages/Ajaxified.java Wed Sep 10 11:09:35 2008
@@ -0,0 +1,46 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.example.upload.pages;
+
+import org.apache.tapestry5.Block;
+import org.apache.tapestry5.RenderSupport;
+import org.apache.tapestry5.annotations.Environmental;
+import org.apache.tapestry5.annotations.InjectComponent;
+import org.apache.tapestry5.corelib.components.FormInjector;
+import org.apache.tapestry5.ioc.annotations.Inject;
+
+public class Ajaxified extends Start
+{
+ @Inject
+ private Block content;
+
+ @InjectComponent
+ private FormInjector injector;
+
+ @Environmental
+ private RenderSupport renderSupport;
+
+ Object onActionFromInjector()
+ {
+ return content;
+ }
+
+ void afterRender()
+ {
+ renderSupport.addScript(
+ "$('trigger').observe('click', function(event) { $('%s').trigger(); Event.stop(event); });",
+ injector.getClientId());
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/example/upload/services/AppModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/example/upload/services/AppModule.java?rev=693917&r1=693916&r2=693917&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/example/upload/services/AppModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-upload/src/test/java/org/example/upload/services/AppModule.java Wed Sep 10 11:09:35 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,6 +14,8 @@
package org.example.upload.services;
+import org.apache.tapestry5.SymbolConstants;
+import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.annotations.SubModule;
import org.apache.tapestry5.upload.services.UploadModule;
@@ -24,5 +26,8 @@
@SubModule(UploadModule.class)
public class AppModule
{
-
+ public static void contributeApplicationDefaults(MappedConfiguration<String, String> configuration)
+ {
+ configuration.add(SymbolConstants.PRODUCTION_MODE, "false");
+ }
}
Added: tapestry/tapestry5/trunk/tapestry-upload/src/test/webapp/Ajaxified.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-upload/src/test/webapp/Ajaxified.tml?rev=693917&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-upload/src/test/webapp/Ajaxified.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-upload/src/test/webapp/Ajaxified.tml Wed Sep 10 11:09:35 2008
@@ -0,0 +1,29 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+ <head>
+ <title>Ajaxified</title>
+ </head>
+ <body>
+ <p>
+ This test of the upload component checks Ajax related behavior.
+ </p>
+ <t:form>
+ <t:errors/>
+ <t:forminjector t:id="injector">
+ <a href="#" id="trigger">add row</a>
+ </t:forminjector>
+
+ <br/>
+ <input type="submit" value="Upload"/>
+ </t:form>
+ <t:if test="file">
+ <p>File: ${file.filePath}</p>
+ <p>Size: ${file.size}</p>
+ </t:if>
+
+ <t:block id="content">
+ <t:label for="file"/>
+ <input t:type="upload" t:id="file" validate="required"/>
+
+ </t:block>
+ </body>
+</html>
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-upload/src/test/webapp/Start.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-upload/src/test/webapp/Start.tml?rev=693917&r1=693916&r2=693917&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-upload/src/test/webapp/Start.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-upload/src/test/webapp/Start.tml Wed Sep 10 11:09:35 2008
@@ -1,19 +1,4 @@
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
- <!--
- Copyright 2007, 2008 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
<head>
<title>Start Page</title>
</head>