File download works from g:link but doesn't work from g:imageButton - grails

I need to change a file download "button" from a g:link to a g:imageButton. They both call the same method in the controller with the same parameters. The g:link and g:imageButton both execute the same code with the same parameters so far as I can tell. The new g:imageButton doesn't give me a csv file download, however. It executes without any problems, but doesn't create the file download.
Both use GET. The g:link (which works) gives this message in the console:
Resource interpreted as Document but transferred with MIME type text/csv:
Why would changing from a g:link to a g:imageButton cause the file download to stop working?
Thanks.

The solution was to use g:actionSubmitImage. g:imageButton isn't in the grails 2 docs, but it works in other places in our code base that are not doing file downloads.

Related

Generate URL of resources that are handled by Grails AssetPipeline

I need to access a local JSON file. Since Grails 2.4 implements the AssetPipeline plugin by default, I saved my local JSON file at:
/grails-app/assets/javascript/vendor/me/json/local.json
Now what I need is to generate a URL to this JSON file, to be used as a function parameter on my JavaScript's $.getJSON() . I've tried using:
var URL.local = ""${ raw(asset.assetPath(src: "local.json")) }";
but it generates an invalid link:
console.log(URL.local);
// prints /project/assets/local.json
// instead of /project/assets/vendor/me/json/local.json
I also encountered the same scenario with images that are handled by AssetPipeline1.9.9— that are supposed to be inserted dynamically on the page. How can I generate the URL pointing this resource? I know, I can always provide a static String for the URL, but it seems there would be a more proper solution.
EDIT
I was asked if I could move the local JSON file directly under the assets/javascript root directory instead of placing it under a subdirectory to for an easier solution. I prefer not to, for organization purposes.
Have you tried asset.assetPath(src: "/me/json/local.json")
The assets plugin looks in all of the immediate children of assets/. Your local.json file would need to be placed in /project/assets/foo/ for your current code to pick it up.
Check out the relevant documentation here which contains an example.
The first level deep within the assets folder is simply used for organization purposes and can contain folders of any name you wish. File types also don't need to be in any specific folder. These folders are omitted from the URL mappings and relative path calculations.

Using signature file in script

I like using .fsi signature files to control visibility. However, if I have both Foo.fsi and Foo.fs files in my solution, and #load "Foo.fs" in a script, it doesn't seem like the corresponding signature file gets used. If I do:
#load "Foo.fsi"
#load "Foo.fs"
... then the desired visibility control happens. Is this the recommended way to achieve this, or is there a better way to do it? In a perfect world, one would like to see the signature file automatically loaded, too.
Not a final answer, but a better way.
From reading Expert F# 4.0 one can do
#load "Foo.fsi" "Foo.fs" "Foo.fsx"
All three loads are on one line.
TL;DR
The link to the book is via WolrdCat just put in a zip code and it will show you locations near there where the book can be found.

Grails file upload with image name

I have a grails controller to handle uploaded files.
Now the problem is that i dont know by which name user will upload the file.
request.getFile(fileName)
I dont know the 'fileName'.
Please let me know how to handle anonymous file upload. These files are being uploaded from a javascript rich text editor and the name of the file input is comes different with each request.
Please help.
you should dump the parmas and inspect which is varible is holding the filename it might not be the varible filename holding the actual file name. so , if u dont have the file name you would have the file handle to proceeed uploading so do as follow :
1.DUMP parmas like
log.debug("Value of Parmas"+parmas.each{it.value()})
or
println("Value of Parmas"+parmas.each{it.value()})
on your console window or what ever using the browser look for a common name that you will use further to get the file handle usually called 'filename'.

Delphi overwrite file and wrong modified date time

I'd like to get a file last modified time in Delphi.
Normally something like FileAge() would do the trick, only the problem is: if I overwrite *File A* with File B using CopyFile, File A's modified date is not updated with current overwrite time as it should(?)
I get that: CopyFile also copy file attributes, but I really need to get the modified date that also works when a file is overwritten.
Is there such function? My whole application relies on modification time to decide whether or not I should proceed with files!
EDIT Just to clarify: I'm only monitoring the files. It's not my application who's modifying them.
The documentation for CopyFile says:
File attributes for the existing file are copied to the new file.
Which means that you cannot use base your program on the last modified attribute of the file, or indeed any attribute of the file. Indeed there are all sorts of ways for the last modified attribute of the file to change. It can in fact go backwards in time.
Instead I suggest that you use ReadDirectoryChangesW to keep track of modifications. That will allow you to receive notifications whenever a file is modified. You can write your program in an event based manner based on the ReadDirectoryChangesW API.
If you can't use ReadDirectoryChangesW and the file attributes, then you'll have to base your decisions on the contents of the file.

Help-balloons in Grails

I am using the help-balloons plugin
I would like to use it parametrized. I mean, the messages should come from a properties file. In the documentation appears the following:
<g:helpBalloon code="user.name" suffix=".help"/>
In this last example, the code attribute is used to look up the balloon's title within the message bundle and then the suffix is added to the code (producing user.name.help in our example) as the key to be used for looking up the content of the balloon.
My question is:
Where should be located this properties file (message bundle)?
Can I have one message bundle per controller?
Luis
if you looked at the source code for the help balloon tag, it literally uses the grails interationalization code to render the message if given a key. http://fisheye.codehaus.org/browse/grails-plugins/grails-help-balloons/trunk/grails-app/taglib/HelpBalloonTagLib.groovy?r=45243
check out this page http://www.grails.org/doc/1.0.x/guide/10.%20Internationalization.html it tells you where and how to name the file for message bundles.
as for a message bundle per controller, it doesnt seem like you can (at least not apparent from the documentation). but you can hack it by prefixing the message key by the controller name, and thus use the same message bundle file (message.properties_ but still be able to namespace each message.
Where are the Resource bundles:
There is a directory under grails-app called i18n where all the generated resource files are placed, start looking there and see how they are used in the app.
You may be able to just place multiple message files for your controllers in there for organization, just be careful of reusing keys as I'm not sure how that will be handled off hand.
How to access them:
Maybe this will help I hope:
http://www.nabble.com/Organizing-message-bundles-tt16169280.html#a16169280

Resources