Grails + GWT - using the same Date Format
I am developing an app using Grails
and GWT
for a client side.
I want to use the same date format
both on the client side and on the server side (preferably defined in one file).
So far i've understood that Grails got it's own mechanism for internationalization (grails-app/i18n
). I know i can access these messages from any server code using app context.
I can also access any resource file inside web-app
directory.
For the client side, i can use ConstantsWithLookup
interface and GWT.Create(...)
to get an instance of it.
But, i still haven't found good solution to i开发者_如何学Pythonntegrate these two together, so i have date format
defined in one place. Any ideas or tips?
Thanks, Sergey
After digging into Grails more, i came to a solution.
I've put constant into .properties
file under grails-app/i18n
.
Then, i hook to eventCompileEnd
and i copy resources from grails-app/i18n
to specific package in target\generated-sources
.
After this step is completed, i generate google I18N interfaces using copied property files.
I've put this functionality to separate plugin.
_Events.groovy:
includeTargets << new File("${myPluginDir}/scripts/_MyInternal.groovy")
eventCompileEnd = {
internalCopyMessageResources();
}
eventCopyMessageResourcesEnd = {
generateI18NInterface();
}
Now it is possible to access localized data from server side and from client side.
精彩评论