You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by matthieu martin <ma...@gmail.com> on 2008/03/13 15:55:19 UTC

ajax file upload

Hi all !

I have a rather disturbing issue with a file upload.

I have the <s:file> tag used along with a form. This works just fine, I get
my files on the server. In my action, I move my file where I want to, and I
create my entry in the database. I refresh my div containing my images.

The problem is this one : I do my upload, my topics are notified, my div is
refreshed. I get a javascript error : "dojo is not defined" (even though I
do have <s:head theme="ajax"/> in my header...) and a stacktrace underneath
showing a very confusing error : a NullPointerException in my action. I
checked my code, nothing special, I change my code, add some lines, retry
and it gives me the exact same message (same line).

On the client side, instead of having the content of my div I have this :
[object HTMLDocument]

The weirdest thing is that if I refresh, everything works fine, I have my
div with everything I want.

I saw on the web that it might be caused by the handleAs attribute of the
dojo widget, when it's set to text it works fine, but when it's set to html
this message appears. As I want to display images, it could be linked, but
why is it working when I refresh my page.

The last thing is that my form containing the <s:file> tag is submitted via
an ajax submit tag.

Here are relevant pieces of code for this matter.

The upload form :

<s:form action="addFileToGallery" enctype="multipart/form-data">

<s:file name="images" id="images" accept="*" />

<s:submit theme="ajax" targets="gallery_images" notifyTopics="/addFile"/>

</s:form>

The stacktrace indicates a line the method addFile which is the method
pointed by the addFileToGallery action:

<action name="addFileToGallery" method="addFile" class="galleryAction">

<result>pages/admin/gallery/galleryFiche.jsp</result>

<result name="input">pages/admin/gallery/galleryFiche.jsp</result>

</action>

The div containing the images

<s:url action="viewFileOfGallery" id="viewFileOfGallery"/>

<s:div id="gallery_images" theme="ajax" cssStyle="border:black solid 1px;"
href="%{viewFileOfGallery}" loadingText="Loading ..."
listenTopics="/refreshGalleryImages" />



There it is, thanks in advance for any kind of help you may provide !



Matthieu