Discussion:
Updating a div as a response to a controller action?
Gregory Pierce
2007-01-22 22:52:43 UTC
Permalink
OKay, so I have something that I think should be pretty
straightforward, but I'm not sure what the proper way is to implement
this. I have a table that is listing the files in a directory on the
server and I have an upload button there. When its clicked, a div
appears that shows the file upload interface. When I click the
upload, the upload closure in my FileController is called, but after
its done - I want to refresh the div that is showing the list of
files. I'm not sure how to accomplish this. I know I shouldn't have
any script or anything in the controller (because that would be
evil), but I don't want to go to a gsp file either. All I really want
is to have a default render behavior when that action is completed.

Any ideas?

---------------------------------------------------------------------
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
Alex Shneyderman
2007-01-23 05:11:23 UTC
Permalink
Post by Gregory Pierce
OKay, so I have something that I think should be pretty
straightforward, but I'm not sure what the proper way is to implement
this. I have a table that is listing the files in a directory on the
server and I have an upload button there. When its clicked, a div
appears that shows the file upload interface. When I click the
upload, the upload closure in my FileController is called, but after
its done - I want to refresh the div that is showing the list of
files. I'm not sure how to accomplish this. I know I shouldn't have
any script or anything in the controller (because that would be
evil), but I don't want to go to a gsp file either. All I really want
is to have a default render behavior when that action is completed.
Any ideas?
I think you should be able to render from within your controller:

def upload = {
...
render (template:'/views/relative/path/myview',
model:[book:book,author:author])
}

I never tried it is worth consideration :-)
now the result of this could be updated with prototype:

$(mydivconatainer).update(renderedText)

---------------------------------------------------------------------
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
Gregory Pierce
2007-01-23 05:40:38 UTC
Permalink
I almost got this working, but there appears to be a bug if I use
this as a formRemote:

<div id="uploadFile" style="display:none">
<br />
<br />
<g:formRemote name="uploadForm"
update="file"
url="[action:'upload', controller:'file']"

enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">

<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:formRemote>
</div>

With a controller that looks like this:

def upload =
{
println "processing upload"

def file = request.getFile('myFile')

println file.getOriginalFilename()


if ( file && !file.empty )
{
println "saving this file"
file.transferTo( new java.io.File("${fileDirectory}$
{file.originalFilename}" ) )
}
else
{
println "something is wrong, can't render"
}

fileList = []

def directory = new java.io.File( fileDirectory )

directory.eachFile
{
fileList << it
}

render( template: 'files' )
}


This was working when I was just using forms, but it definitely
doesn't work with formRemote as I expected it should.
Post by Alex Shneyderman
Post by Gregory Pierce
OKay, so I have something that I think should be pretty
straightforward, but I'm not sure what the proper way is to implement
this. I have a table that is listing the files in a directory on the
server and I have an upload button there. When its clicked, a div
appears that shows the file upload interface. When I click the
upload, the upload closure in my FileController is called, but after
its done - I want to refresh the div that is showing the list of
files. I'm not sure how to accomplish this. I know I shouldn't have
any script or anything in the controller (because that would be
evil), but I don't want to go to a gsp file either. All I really want
is to have a default render behavior when that action is completed.
Any ideas?
def upload = {
...
render (template:'/views/relative/path/myview',
model:[book:book,author:author])
}
I never tried it is worth consideration :-)
$(mydivconatainer).update(renderedText)
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
Gregory Pierce
2007-01-23 05:42:13 UTC
Permalink
Forgot to post the error. There seems to be some issue with the file
actually getting submitted:

Grails Runtime Exception

Error Details

Message: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is applicable
for argument types: (java.lang.String) values: {"myFile"}
Caused by: groovy.lang.MissingMethodException: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is applicable
for argument types: (java.lang.String) values: {"myFile"}
Class: FileController
At Line: [41]
Code Snippet:
41: def file = request.getFile('myFile')
42:
Stack Trace

org.codehaus.groovy.runtime.InvokerInvocationException:
groovy.lang.MissingMethodException: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is applicable
for argument types: (java.lang.String) values: {"myFile"} at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke
(MetaClassHelper.java:657) at groovy.lang.MetaClassImpl.invokeMethod
(MetaClassImpl.java:367) at groovy.lang.Closure.call(Closure.java:
175) at groovy.lang.Closure.call(Closure.java:170) at
...
Post by Gregory Pierce
I almost got this working, but there appears to be a bug if I use
<div id="uploadFile" style="display:none">
<br />
<br />
<g:formRemote name="uploadForm"
update="file"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:formRemote>
</div>
def upload =
{
println "processing upload"
def file = request.getFile('myFile')
println file.getOriginalFilename()
if ( file && !file.empty )
{
println "saving this file"
file.transferTo( new java.io.File("${fileDirectory}$
{file.originalFilename}" ) )
}
else
{
println "something is wrong, can't render"
}
fileList = []
def directory = new java.io.File( fileDirectory )
directory.eachFile
{
fileList << it
}
render( template: 'files' )
}
This was working when I was just using forms, but it definitely
doesn't work with formRemote as I expected it should.
Post by Alex Shneyderman
Post by Gregory Pierce
OKay, so I have something that I think should be pretty
straightforward, but I'm not sure what the proper way is to
implement
this. I have a table that is listing the files in a directory on the
server and I have an upload button there. When its clicked, a div
appears that shows the file upload interface. When I click the
upload, the upload closure in my FileController is called, but after
its done - I want to refresh the div that is showing the list of
files. I'm not sure how to accomplish this. I know I shouldn't have
any script or anything in the controller (because that would be
evil), but I don't want to go to a gsp file either. All I really want
is to have a default render behavior when that action is completed.
Any ideas?
def upload = {
...
render (template:'/views/relative/path/myview',
model:[book:book,author:author])
}
I never tried it is worth consideration :-)
$(mydivconatainer).update(renderedText)
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Alex Shneyderman
2007-01-23 06:15:16 UTC
Permalink
when you get to the page that does the submission how does your html
look like?

it seems to me that request does not get wrapped into multipart request.
Maybe the form is not generated by formRemote as it should?
Post by Gregory Pierce
Forgot to post the error. There seems to be some issue with the file
Grails Runtime Exception
Error Details
Message: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"}
Caused by: groovy.lang.MissingMethodException: No signature
of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"}
Class: FileController
At Line: [41]
41: def file = request.getFile('myFile')
Stack Trace
groovy.lang.MissingMethodException: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"} at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:657)
at
groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:367)
at groovy.lang.Closure.call(Closure.java:175) at
groovy.lang.Closure.call(Closure.java:170) at
...
I almost got this working, but there appears to be a bug if I use this as a
<div id="uploadFile" style="display:none">
<br />
<br />
<g:formRemote name="uploadForm"
update="file"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:formRemote>
</div>
def upload =
{
println "processing upload"
def file = request.getFile('myFile')
println file.getOriginalFilename()
if ( file && !file.empty )
{
println "saving this file"
file.transferTo( new
java.io.File("${fileDirectory}${file.originalFilename}" ) )
}
else
{
println "something is wrong, can't render"
}
fileList = []
def directory = new java.io.File( fileDirectory )
directory.eachFile
{
fileList << it
}
render( template: 'files' )
}
This was working when I was just using forms, but it definitely doesn't work
with formRemote as I expected it should.
OKay, so I have something that I think should be pretty
straightforward, but I'm not sure what the proper way is to implement
this. I have a table that is listing the files in a directory on the
server and I have an upload button there. When its clicked, a div
appears that shows the file upload interface. When I click the
upload, the upload closure in my FileController is called, but after
its done - I want to refresh the div that is showing the list of
files. I'm not sure how to accomplish this. I know I shouldn't have
any script or anything in the controller (because that would be
evil), but I don't want to go to a gsp file either. All I really want
is to have a default render behavior when that action is completed.
Any ideas?
def upload = {
...
render (template:'/views/relative/path/myview',
model:[book:book,author:author])
}
I never tried it is worth consideration :-)
$(mydivconatainer).update(renderedText)
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Thanks,
Alex.

---------------------------------------------------------------------
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
Gregory Pierce
2007-01-23 06:45:13 UTC
Permalink
Looks to be a general issue with the Ajax tags. I tried this with
regular form and submitToRemote and got the same issue until I just
went with a regular form:

<div id="uploadFile" style="display:none">
<br />
<br />
<g:form name="uploadForm"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">

<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:form>
</div>

If I go to an alternative Ajax approach:

<div id="uploadFile" style="display:none">
<br />
<br />
<g:form name="uploadForm"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">

<input type="file" name="myFile" />
<g:submitToRemote url="[action:'upload',
controller:'file']"
before="alert('before submit')"
after="alert('finish submit')">Submit</
g:submitToRemote>
</g:form>
</div>



[groovy] groovy.lang.MissingMethodException: No signature of
method org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"}
[groovy] at groovy.lang.MetaClassImpl.invokeMethod
(MetaClassImpl.java:379)
[groovy] at org.codehaus.groovy.runtime.Invoker.invokeMethod
(Invoker.java:147)
[groovy] at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod
(InvokerHelper.java:104)
[groovy] at
org.codehaus.groovy.grails.web.servlet.GrailsHttpServletRequest.invokeMe
thod(GrailsHttpServletRequest.java:198)

Somehow the Ajax method isn't actually uploading content and I'm
getting stuck in limbo with only a file getting passed.


Since the DOM is being built on the fly, the complete HTML isn't
available as those divs are generated in a template which is being
rendered in the view (and that part is happening just fine).
Post by Alex Shneyderman
when you get to the page that does the submission how does your html
look like?
it seems to me that request does not get wrapped into multipart request.
Maybe the form is not generated by formRemote as it should?
Post by Gregory Pierce
Forgot to post the error. There seems to be some issue with the file
Grails Runtime Exception
Error Details
Message: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"}
Caused by: groovy.lang.MissingMethodException: No signature
of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"}
Class: FileController
At Line: [41]
41: def file = request.getFile('myFile')
Stack Trace
groovy.lang.MissingMethodException: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
{"myFile"} at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke
(MetaClassHelper.java:657)
at
groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:367)
at groovy.lang.Closure.call(Closure.java:175) at
groovy.lang.Closure.call(Closure.java:170) at
...
I almost got this working, but there appears to be a bug if I use this as a
<div id="uploadFile" style="display:none">
<br />
<br />
<g:formRemote name="uploadForm"
update="file"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:formRemote>
</div>
def upload =
{
println "processing upload"
def file = request.getFile('myFile')
println file.getOriginalFilename()
if ( file && !file.empty )
{
println "saving this file"
file.transferTo( new
java.io.File("${fileDirectory}${file.originalFilename}" ) )
}
else
{
println "something is wrong, can't render"
}
fileList = []
def directory = new java.io.File( fileDirectory )
directory.eachFile
{
fileList << it
}
render( template: 'files' )
}
This was working when I was just using forms, but it definitely doesn't work
with formRemote as I expected it should.
OKay, so I have something that I think should be pretty
straightforward, but I'm not sure what the proper way is to implement
this. I have a table that is listing the files in a directory on the
server and I have an upload button there. When its clicked, a div
appears that shows the file upload interface. When I click the
upload, the upload closure in my FileController is called, but after
its done - I want to refresh the div that is showing the list of
files. I'm not sure how to accomplish this. I know I shouldn't have
any script or anything in the controller (because that would be
evil), but I don't want to go to a gsp file either. All I really want
is to have a default render behavior when that action is completed.
Any ideas?
def upload = {
...
render (template:'/views/relative/path/myview',
model:[book:book,author:author])
}
I never tried it is worth consideration :-)
$(mydivconatainer).update(renderedText)
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Thanks,
Alex.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
Graeme Rocher
2007-01-23 07:50:15 UTC
Permalink
I don't believe Prototype supports file uploads using the Ajax object,
correct me if I'm wrong. For this you need to use something like Dojo

Cheers
Post by Gregory Pierce
Looks to be a general issue with the Ajax tags. I tried this with
regular form and submitToRemote and got the same issue until I just
<div id="uploadFile" style="display:none">
<br />
<br />
<g:form name="uploadForm"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:form>
</div>
<div id="uploadFile" style="display:none">
<br />
<br />
<g:form name="uploadForm"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<g:submitToRemote url="[action:'upload',
controller:'file']"
before="alert('before submit')"
after="alert('finish submit')">Submit</
g:submitToRemote>
</g:form>
</div>
[groovy] groovy.lang.MissingMethodException: No signature of
method org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"}
[groovy] at groovy.lang.MetaClassImpl.invokeMethod
(MetaClassImpl.java:379)
[groovy] at org.codehaus.groovy.runtime.Invoker.invokeMethod
(Invoker.java:147)
[groovy] at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod
(InvokerHelper.java:104)
[groovy] at
org.codehaus.groovy.grails.web.servlet.GrailsHttpServletRequest.invokeMe
thod(GrailsHttpServletRequest.java:198)
Somehow the Ajax method isn't actually uploading content and I'm
getting stuck in limbo with only a file getting passed.
Since the DOM is being built on the fly, the complete HTML isn't
available as those divs are generated in a template which is being
rendered in the view (and that part is happening just fine).
Post by Alex Shneyderman
when you get to the page that does the submission how does your html
look like?
it seems to me that request does not get wrapped into multipart request.
Maybe the form is not generated by formRemote as it should?
Post by Gregory Pierce
Forgot to post the error. There seems to be some issue with the file
Grails Runtime Exception
Error Details
Message: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"}
Caused by: groovy.lang.MissingMethodException: No signature
of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"}
Class: FileController
At Line: [41]
41: def file = request.getFile('myFile')
Stack Trace
groovy.lang.MissingMethodException: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
{"myFile"} at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke
(MetaClassHelper.java:657)
at
groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:367)
at groovy.lang.Closure.call(Closure.java:175) at
groovy.lang.Closure.call(Closure.java:170) at
...
I almost got this working, but there appears to be a bug if I use this as a
<div id="uploadFile" style="display:none">
<br />
<br />
<g:formRemote name="uploadForm"
update="file"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:formRemote>
</div>
def upload =
{
println "processing upload"
def file = request.getFile('myFile')
println file.getOriginalFilename()
if ( file && !file.empty )
{
println "saving this file"
file.transferTo( new
java.io.File("${fileDirectory}${file.originalFilename}" ) )
}
else
{
println "something is wrong, can't render"
}
fileList = []
def directory = new java.io.File( fileDirectory )
directory.eachFile
{
fileList << it
}
render( template: 'files' )
}
This was working when I was just using forms, but it definitely doesn't work
with formRemote as I expected it should.
OKay, so I have something that I think should be pretty
straightforward, but I'm not sure what the proper way is to implement
this. I have a table that is listing the files in a directory on the
server and I have an upload button there. When its clicked, a div
appears that shows the file upload interface. When I click the
upload, the upload closure in my FileController is called, but after
its done - I want to refresh the div that is showing the list of
files. I'm not sure how to accomplish this. I know I shouldn't have
any script or anything in the controller (because that would be
evil), but I don't want to go to a gsp file either. All I really want
is to have a default render behavior when that action is completed.
Any ideas?
def upload = {
...
render (template:'/views/relative/path/myview',
model:[book:book,author:author])
}
I never tried it is worth consideration :-)
$(mydivconatainer).update(renderedText)
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Thanks,
Alex.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
Sven Haiges
2007-01-23 08:34:31 UTC
Permalink
Yes, Dojo seems to be a good choice here. But simply using formRemote with
Dojo also won't help. The problem is that you have to to require a few Dojo
imports:

dojo.require("dojo.io.*");
dojo.require("dojo.io.IframeIO");

IFrameIO will make File Uploads with Dojo possible. But then there is
another catch: any response has to be wrapped in an html page with one
textarea. In your dojo handle-Method, you can nthen access the content of
that textarea.

Very complicated, but that's how it works.

I was posting this a few weeks ago, I bet if you search for dojo file
uploads with nabble you can find my post. I am wondering how we could change
the AJAX tags to magically work with file uploads, but as you can see, it's
a bit complicated.

Cheers\
Sven
Post by Graeme Rocher
I don't believe Prototype supports file uploads using the Ajax object,
correct me if I'm wrong. For this you need to use something like Dojo
Cheers
Post by Gregory Pierce
Looks to be a general issue with the Ajax tags. I tried this with
regular form and submitToRemote and got the same issue until I just
<div id="uploadFile" style="display:none">
<br />
<br />
<g:form name="uploadForm"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:form>
</div>
<div id="uploadFile" style="display:none">
<br />
<br />
<g:form name="uploadForm"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<g:submitToRemote url="[action:'upload',
controller:'file']"
before="alert('before submit')"
after="alert('finish submit')">Submit</
g:submitToRemote>
</g:form>
</div>
[groovy] groovy.lang.MissingMethodException: No signature of
method org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"}
[groovy] at groovy.lang.MetaClassImpl.invokeMethod
(MetaClassImpl.java:379)
[groovy] at org.codehaus.groovy.runtime.Invoker.invokeMethod
(Invoker.java:147)
[groovy] at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod
(InvokerHelper.java:104)
[groovy] at
org.codehaus.groovy.grails.web.servlet.GrailsHttpServletRequest.invokeMe
thod(GrailsHttpServletRequest.java:198)
Somehow the Ajax method isn't actually uploading content and I'm
getting stuck in limbo with only a file getting passed.
Since the DOM is being built on the fly, the complete HTML isn't
available as those divs are generated in a template which is being
rendered in the view (and that part is happening just fine).
Post by Alex Shneyderman
when you get to the page that does the submission how does your html
look like?
it seems to me that request does not get wrapped into multipart request.
Maybe the form is not generated by formRemote as it should?
Post by Gregory Pierce
Forgot to post the error. There seems to be some issue with the file
Grails Runtime Exception
Error Details
Message: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"}
Caused by: groovy.lang.MissingMethodException: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"}
Class: FileController
At Line: [41]
41: def file = request.getFile('myFile')
Stack Trace
groovy.lang.MissingMethodException: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
{"myFile"} at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke
(MetaClassHelper.java:657)
at
groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:367)
at groovy.lang.Closure.call(Closure.java:175) at
groovy.lang.Closure.call(Closure.java:170) at
...
I almost got this working, but there appears to be a bug if I use this as a
<div id="uploadFile" style="display:none">
<br />
<br />
<g:formRemote name="uploadForm"
update="file"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:formRemote>
</div>
def upload =
{
println "processing upload"
def file = request.getFile('myFile')
println file.getOriginalFilename()
if ( file && !file.empty )
{
println "saving this file"
file.transferTo( new
java.io.File("${fileDirectory}${file.originalFilename}" ) )
}
else
{
println "something is wrong, can't render"
}
fileList = []
def directory = new java.io.File( fileDirectory )
directory.eachFile
{
fileList << it
}
render( template: 'files' )
}
This was working when I was just using forms, but it definitely doesn't work
with formRemote as I expected it should.
OKay, so I have something that I think should be pretty
straightforward, but I'm not sure what the proper way is to implement
this. I have a table that is listing the files in a directory on the
server and I have an upload button there. When its clicked, a div
appears that shows the file upload interface. When I click the
upload, the upload closure in my FileController is called, but after
its done - I want to refresh the div that is showing the list of
files. I'm not sure how to accomplish this. I know I shouldn't have
any script or anything in the controller (because that would be
evil), but I don't want to go to a gsp file either. All I really want
is to have a default render behavior when that action is completed.
Any ideas?
def upload = {
...
render (template:'/views/relative/path/myview',
model:[book:book,author:author])
}
I never tried it is worth consideration :-)
$(mydivconatainer).update(renderedText)
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Thanks,
Alex.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Graeme Rocher
Grails Project Lead
http://grails.org
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Sven Haiges
***@googlemail.com

Skype: hansamann
Personal Homepage, Wiki & Blog: http://www.svenhaiges.de

Subscribe to the Grails Podcast:
http://hansamann.podspot.de/rss
Sven Haiges
2007-01-23 08:36:53 UTC
Permalink
Found the thread:
http://www.nabble.com/Dojo-with-FileUpload%2C-JSON---Grails-JSON-Renderer-tf2706664.html#a7557105

Cheers\
Sven
Post by Sven Haiges
Yes, Dojo seems to be a good choice here. But simply using formRemote with
Dojo also won't help. The problem is that you have to to require a few Dojo
dojo.require("dojo.io.*");
dojo.require ("dojo.io.IframeIO");
IFrameIO will make File Uploads with Dojo possible. But then there is
another catch: any response has to be wrapped in an html page with one
textarea. In your dojo handle-Method, you can nthen access the content of
that textarea.
Very complicated, but that's how it works.
I was posting this a few weeks ago, I bet if you search for dojo file
uploads with nabble you can find my post. I am wondering how we could change
the AJAX tags to magically work with file uploads, but as you can see, it's
a bit complicated.
Cheers\
Sven
Post by Graeme Rocher
I don't believe Prototype supports file uploads using the Ajax object,
correct me if I'm wrong. For this you need to use something like Dojo
Cheers
Post by Gregory Pierce
Looks to be a general issue with the Ajax tags. I tried this with
regular form and submitToRemote and got the same issue until I just
<div id="uploadFile" style="display:none">
<br />
<br />
<g:form name="uploadForm"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:form>
</div>
<div id="uploadFile" style="display:none">
<br />
<br />
<g:form name="uploadForm"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<g:submitToRemote url="[action:'upload',
controller:'file']"
before="alert('before submit')"
after="alert('finish submit')">Submit</
g:submitToRemote>
</g:form>
</div>
[groovy] groovy.lang.MissingMethodException: No signature of
method org.mortbay.jetty.servlet.ServletHttpRequest.getFile () is
applicable for argument types: (java.lang.String) values: {"myFile"}
[groovy] at groovy.lang.MetaClassImpl.invokeMethod
(MetaClassImpl.java:379)
[groovy] at org.codehaus.groovy.runtime.Invoker.invokeMethod
(Invoker.java:147)
[groovy] at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod
(InvokerHelper.java:104)
[groovy] at
org.codehaus.groovy.grails.web.servlet.GrailsHttpServletRequest.invokeMe
Post by Gregory Pierce
thod(GrailsHttpServletRequest.java:198)
Somehow the Ajax method isn't actually uploading content and I'm
getting stuck in limbo with only a file getting passed.
Since the DOM is being built on the fly, the complete HTML isn't
available as those divs are generated in a template which is being
rendered in the view (and that part is happening just fine).
Post by Alex Shneyderman
when you get to the page that does the submission how does your html
look like?
it seems to me that request does not get wrapped into multipart request.
Maybe the form is not generated by formRemote as it should?
Post by Gregory Pierce
Forgot to post the error. There seems to be some issue with the
file
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
Grails Runtime Exception
Error Details
Message: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
{"myFile"}
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
Caused by: groovy.lang.MissingMethodException : No signature
of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
{"myFile"}
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
Class: FileController
At Line: [41]
41: def file = request.getFile('myFile')
Stack Trace
groovy.lang.MissingMethodException: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"} at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke
(MetaClassHelper.java:657)
at
groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:367)
at groovy.lang.Closure.call(Closure.java:175) at
groovy.lang.Closure.call(Closure.java:170) at
...
I almost got this working, but there appears to be a bug if I use this as a
<div id="uploadFile" style="display:none">
<br />
<br />
<g:formRemote name="uploadForm"
update="file"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:formRemote>
</div>
def upload =
{
println "processing upload"
def file = request.getFile('myFile')
println file.getOriginalFilename()
if ( file && !file.empty )
{
println "saving this file"
file.transferTo( new
java.io.File("${fileDirectory}${file.originalFilename}" ) )
}
else
{
println "something is wrong, can't render"
}
fileList = []
def directory = new java.io.File( fileDirectory )
directory.eachFile
{
fileList << it
}
render( template: 'files' )
}
This was working when I was just using forms, but it definitely doesn't work
with formRemote as I expected it should.
OKay, so I have something that I think should be pretty
straightforward, but I'm not sure what the proper way is to
implement
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
this. I have a table that is listing the files in a directory on
the
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
server and I have an upload button there. When its clicked, a div
appears that shows the file upload interface. When I click the
upload, the upload closure in my FileController is called, but
after
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
its done - I want to refresh the div that is showing the list of
files. I'm not sure how to accomplish this. I know I shouldn't have
any script or anything in the controller (because that would be
evil), but I don't want to go to a gsp file either. All I really
want
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
is to have a default render behavior when that action is completed.
Any ideas?
def upload = {
...
render (template:'/views/relative/path/myview',
model:[book:book,author:author])
}
I never tried it is worth consideration :-)
$(mydivconatainer).update(renderedText)
---------------------------------------------------------------------
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
http://xircles.codehaus.org/manage_email
--
Thanks,
Alex.
---------------------------------------------------------------------
Post by Gregory Pierce
Post by Alex Shneyderman
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Graeme Rocher
Grails Project Lead
http://grails.org
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Sven Haiges
Skype: hansamann
Personal Homepage, Wiki & Blog: http://www.svenhaiges.de
http://hansamann.podspot.de/rss
--
Sven Haiges
***@googlemail.com

Skype: hansamann
Personal Homepage, Wiki & Blog: http://www.svenhaiges.de

Subscribe to the Grails Podcast:
http://hansamann.podspot.de/rss
Gregory Pierce
2007-01-23 15:32:23 UTC
Permalink
Have a more complete example? I tried to follow what was going on,
but can't really tell what you are doing outside the render call.

It would indeed be nice if this was wrapped up in a g:ajaxupload or
similar tag :)
Found the thread: http://www.nabble.com/Dojo-with-FileUpload%2C-
JSON---Grails-JSON-Renderer-tf2706664.html#a7557105
Cheers\
Sven
Yes, Dojo seems to be a good choice here. But simply using
formRemote with Dojo also won't help. The problem is that you have
dojo.require("dojo.io.*");
dojo.require ("dojo.io.IframeIO");
IFrameIO will make File Uploads with Dojo possible. But then there
is another catch: any response has to be wrapped in an html page
with one textarea. In your dojo handle-Method, you can nthen access
the content of that textarea.
Very complicated, but that's how it works.
I was posting this a few weeks ago, I bet if you search for dojo
file uploads with nabble you can find my post. I am wondering how
we could change the AJAX tags to magically work with file uploads,
but as you can see, it's a bit complicated.
Cheers\
Sven
I don't believe Prototype supports file uploads using the Ajax object,
correct me if I'm wrong. For this you need to use something like Dojo
Cheers
Post by Gregory Pierce
Looks to be a general issue with the Ajax tags. I tried this with
regular form and submitToRemote and got the same issue until I just
<div id="uploadFile" style="display:none">
<br />
<br />
<g:form name="uploadForm"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:form>
</div>
<div id="uploadFile" style="display:none">
<br />
<br />
<g:form name="uploadForm"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<g:submitToRemote url="[action:'upload',
controller:'file']"
before="alert('before submit')"
after="alert('finish
submit')">Submit</
Post by Gregory Pierce
g:submitToRemote>
</g:form>
</div>
[groovy] groovy.lang.MissingMethodException: No signature of
method org.mortbay.jetty.servlet.ServletHttpRequest.getFile () is
applicable for argument types: (java.lang.String) values: {"myFile"}
[groovy] at groovy.lang.MetaClassImpl.invokeMethod
(MetaClassImpl.java:379)
[groovy] at org.codehaus.groovy.runtime.Invoker.invokeMethod
(Invoker.java:147)
[groovy] at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod
(InvokerHelper.java:104)
[groovy] at
org.codehaus.groovy.grails.web.servlet.GrailsHttpServletRequest.invoke
Me
Post by Gregory Pierce
thod(GrailsHttpServletRequest.java:198)
Somehow the Ajax method isn't actually uploading content and I'm
getting stuck in limbo with only a file getting passed.
Since the DOM is being built on the fly, the complete HTML isn't
available as those divs are generated in a template which is being
rendered in the view (and that part is happening just fine).
Post by Alex Shneyderman
when you get to the page that does the submission how does your
html
Post by Gregory Pierce
Post by Alex Shneyderman
look like?
it seems to me that request does not get wrapped into multipart request.
Maybe the form is not generated by formRemote as it should?
Post by Gregory Pierce
Forgot to post the error. There seems to be some issue with
the file
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
Grails Runtime Exception
Error Details
Message: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
{"myFile"}
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
Caused by: groovy.lang.MissingMethodException : No signature
of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
{"myFile"}
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
Class: FileController
At Line: [41]
41: def file = request.getFile('myFile')
Stack Trace
groovy.lang.MissingMethodException: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
{"myFile"} at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke
(MetaClassHelper.java:657)
at
groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:367)
at groovy.lang.Closure.call(Closure.java:175) at
groovy.lang.Closure.call(Closure.java:170) at
...
I almost got this working, but there appears to be a bug if I use this as a
<div id="uploadFile" style="display:none">
<br />
<br />
<g:formRemote name="uploadForm"
update="file"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp
('uploadFile')">
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:formRemote>
</div>
def upload =
{
println "processing upload"
def file = request.getFile('myFile')
println file.getOriginalFilename()
if ( file && !file.empty )
{
println "saving this file"
file.transferTo ( new
java.io.File("${fileDirectory}${file.originalFilename}" ) )
}
else
{
println "something is wrong, can't render"
}
fileList = []
def directory = new java.io.File( fileDirectory )
directory.eachFile
{
fileList << it
}
render( template: 'files' )
}
This was working when I was just using forms, but it definitely doesn't work
with formRemote as I expected it should.
OKay, so I have something that I think should be pretty
straightforward, but I'm not sure what the proper way is to
implement
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
this. I have a table that is listing the files in a directory
on the
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
server and I have an upload button there. When its clicked, a div
appears that shows the file upload interface. When I click the
upload, the upload closure in my FileController is called, but
after
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
its done - I want to refresh the div that is showing the list of
files. I'm not sure how to accomplish this. I know I shouldn't
have
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
any script or anything in the controller (because that would be
evil), but I don't want to go to a gsp file either. All I
really want
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
is to have a default render behavior when that action is
completed.
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
Any ideas?
def upload = {
...
render (template:'/views/relative/path/myview',
model:[book:book,author:author])
}
I never tried it is worth consideration :-)
$(mydivconatainer).update(renderedText)
---------------------------------------------------------------------
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
http://xircles.codehaus.org/manage_email
--
Thanks,
Alex.
---------------------------------------------------------------------
Post by Gregory Pierce
Post by Alex Shneyderman
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
Post by Gregory Pierce
http://xircles.codehaus.org/manage_email
--
Graeme Rocher
Grails Project Lead
http://grails.org
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Sven Haiges
Skype: hansamann
Personal Homepage, Wiki & Blog: http://www.svenhaiges.de
http://hansamann.podspot.de/rss
--
Sven Haiges
Skype: hansamann
Personal Homepage, Wiki & Blog: http://www.svenhaiges.de
http://hansamann.podspot.de/rss
Sven Haiges
2007-01-24 08:49:10 UTC
Permalink
Ok,here we go. Below is an example out of my code. Please note that it does
not use the Grails AJAX tags, because my code was getting to specific, so I
felt more comfortable with working in dojo directly. But I am currently
taking another look at the Grails AJAX tags and it might be possible to
submit files with the Grails dojo tags, too.

But for sure you have to do this:

dojo.require("dojo.io.IframeIO

This tells dojo to use an hidden iFrame for the transport of the data.
Otherwise, file uploads are not possible.

Cheers\
Sven

How-to submit a file via AJAX and Dojo:

VIEW

include dojo: <g:javascript library="dojo" />

require at least this:

dojo.require("dojo.io.*");
dojo.require("dojo.io.IframeIO");

//load dojo after HTML DOM is built up
dojo.event.connect(dojo, "loaded", "init");

(put this around <script> tag after loading dojo)

in a function init(), set up teh AJAX FormBind:

function imageForm() {
//ajax form
var form = new dojo.io.FormBind({
// reference your form
formNode: document.forms["imageForm"],
handle: function(type, data, evt)
{
//alert("type: " + type);
if (type == "load")
{

var fileName = data.imageElement.fileName;

...
}
else
{
//error code here
}
spin(false);
},
mimetype: "text/json"
});
}



the form:
<form name="imageForm" id="imageForm"
action="/adm/editor/addImage" method="POST" enctype="multipart/form-data">
<input size="16" name="imageFile" type="file"
accept="image/*" />
<input type="submit" value="Add"
onclick="return checkImageForm();"/>
</form>
CONTROLLER:

def addImage = {
log.info("addImage")

def f = request.getFile('imageFile')

if(f.empty) {
render "No file!"
}
else {
//do sth with the file...



//create response with json builder
java.io.Writer writer = new java.io.StringWriter();
new grails.util.JSonBuilder(writer).json
{
imageElement(fileName:"${session.relUserSpace
}/uploadImages/${f.getOriginalFilename()}")
}
def jsonText = writer.toString()
log.info(jsonText)

render(text:"<html><body><textarea>${jsonText}</textarea></body></html>",contentType:"text/html",encoding:"UTF-8")
}
}
Have a more complete example? I tried to follow what was going on, but
can't really tell what you are doing outside the render call.
It would indeed be nice if this was wrapped up in a g:ajaxupload or
similar tag :)
Found the thread: http://www.nabble.com/Dojo-with-FileUpload%2C-JSON---Grails-JSON-Renderer-tf2706664.html#a7557105
Cheers\
Sven
Post by Sven Haiges
Yes, Dojo seems to be a good choice here. But simply using formRemote
with Dojo also won't help. The problem is that you have to to require a few
dojo.require("dojo.io.*");
dojo.require ("dojo.io.IframeIO");
IFrameIO will make File Uploads with Dojo possible. But then there is
another catch: any response has to be wrapped in an html page with one
textarea. In your dojo handle-Method, you can nthen access the content of
that textarea.
Very complicated, but that's how it works.
I was posting this a few weeks ago, I bet if you search for dojo file
uploads with nabble you can find my post. I am wondering how we could change
the AJAX tags to magically work with file uploads, but as you can see, it's
a bit complicated.
Cheers\
Sven
Post by Graeme Rocher
I don't believe Prototype supports file uploads using the Ajax object,
correct me if I'm wrong. For this you need to use something like Dojo
Cheers
Post by Gregory Pierce
Looks to be a general issue with the Ajax tags. I tried this with
regular form and submitToRemote and got the same issue until I just
<div id="uploadFile" style="display:none">
<br />
<br />
<g:form name="uploadForm"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:form>
</div>
<div id="uploadFile" style="display:none">
<br />
<br />
<g:form name="uploadForm"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp('uploadFile')">
<input type="file" name="myFile" />
<g:submitToRemote url="[action:'upload',
controller:'file']"
before="alert('before submit')"
after="alert('finish
submit')">Submit</
Post by Gregory Pierce
g:submitToRemote>
</g:form>
</div>
[groovy] groovy.lang.MissingMethodException: No signature of
method org.mortbay.jetty.servlet.ServletHttpRequest.getFile () is
applicable for argument types: (java.lang.String) values: {"myFile"}
[groovy] at groovy.lang.MetaClassImpl.invokeMethod
(MetaClassImpl.java:379)
[groovy] at org.codehaus.groovy.runtime.Invoker.invokeMethod
(Invoker.java:147)
[groovy] at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod
(InvokerHelper.java:104)
[groovy] at
org.codehaus.groovy.grails.
web.servlet.GrailsHttpServletRequest.invokeMe
Post by Gregory Pierce
thod(GrailsHttpServletRequest.java:198)
Somehow the Ajax method isn't actually uploading content and I'm
getting stuck in limbo with only a file getting passed.
Since the DOM is being built on the fly, the complete HTML isn't
available as those divs are generated in a template which is being
rendered in the view (and that part is happening just fine).
Post by Alex Shneyderman
when you get to the page that does the submission how does your
html
Post by Gregory Pierce
Post by Alex Shneyderman
look like?
it seems to me that request does not get wrapped into multipart request.
Maybe the form is not generated by formRemote as it should?
Post by Gregory Pierce
Forgot to post the error. There seems to be some issue with the
file
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
Grails Runtime Exception
Error Details
Message: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
{"myFile"}
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
Caused by: groovy.lang.MissingMethodException : No signature
of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
{"myFile"}
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
Class: FileController
At Line: [41]
41: def file = request.getFile('myFile')
Stack Trace
groovy.lang.MissingMethodException: No signature of method
org.mortbay.jetty.servlet.ServletHttpRequest.getFile() is
applicable for argument types: (java.lang.String) values: {"myFile"} at
org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke
(MetaClassHelper.java:657)
at
groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:367)
at groovy.lang.Closure.call(Closure.java:175) at
groovy.lang.Closure.call(Closure.java:170) at
...
I almost got this working, but there appears to be a bug if I use
this as a
<div id="uploadFile" style="display:none">
<br />
<br />
<g:formRemote name="uploadForm"
update="file"
url="[action:'upload', controller:'file']"
enctype="multipart/form-data"
onSuccess="new Effect.BlindUp
('uploadFile')">
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
<input type="file" name="myFile" />
<input type="submit" name="Upload!" />
</g:formRemote>
</div>
def upload =
{
println "processing upload"
def file = request.getFile('myFile')
println file.getOriginalFilename()
if ( file && !file.empty )
{
println "saving this file"
file.transferTo ( new
java.io.File("${fileDirectory}${file.originalFilename}" ) )
}
else
{
println "something is wrong, can't render"
}
fileList = []
def directory = new java.io.File( fileDirectory )
directory.eachFile
{
fileList << it
}
render( template: 'files' )
}
This was working when I was just using forms, but it definitely
doesn't work
with formRemote as I expected it should.
OKay, so I have something that I think should be pretty
straightforward, but I'm not sure what the proper way is to
implement
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
this. I have a table that is listing the files in a directory on
the
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
server and I have an upload button there. When its clicked, a div
appears that shows the file upload interface. When I click the
upload, the upload closure in my FileController is called, but
after
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
its done - I want to refresh the div that is showing the list of
files. I'm not sure how to accomplish this. I know I shouldn't
have
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
any script or anything in the controller (because that would be
evil), but I don't want to go to a gsp file either. All I really
want
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
is to have a default render behavior when that action is
completed.
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
Any ideas?
def upload = {
...
render (template:'/views/relative/path/myview',
model:[book:book,author:author])
}
I never tried it is worth consideration :-)
$(mydivconatainer).update(renderedText)
---------------------------------------------------------------------
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
Post by Gregory Pierce
Post by Alex Shneyderman
Post by Gregory Pierce
http://xircles.codehaus.org/manage_email
--
Thanks,
Alex.
---------------------------------------------------------------------
Post by Gregory Pierce
Post by Alex Shneyderman
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
Post by Gregory Pierce
http://xircles.codehaus.org/manage_email
--
Graeme Rocher
Grails Project Lead
http://grails.org
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
Sven Haiges
Skype: hansamann
Personal Homepage, Wiki & Blog: http://www.svenhaiges.de
http://hansamann.podspot.de/rss
--
Sven Haiges
Skype: hansamann
Personal Homepage, Wiki & Blog: http://www.svenhaiges.de
http://hansamann.podspot.de/rss
--
Sven Haiges
***@googlemail.com

Skype: hansamann
Personal Homepage, Wiki & Blog: http://www.svenhaiges.de

Subscribe to the Grails Podcast:
http://hansamann.podspot.de/rss
Loading...