Why can't you just use resource bundle to get messages?
On 17 août, 10:49, Joe Cole <profilercorporat...@gmail.com> wrote: > What we do is use this code pattern: > > public interface IMessages { > public MyMessages get(); // your messages interface} > > public class Messages { > private static IMessages messages; > public static MyMessages get() { return messages.get(); } > public static void set(IMessages messages) //etc > > } > > Then in our server side initialisation we use: > > ServerMessages implements IMessages { > public MyMessages get(){ > // note, basically pseudocode > Properties properties = new Properties(); > InputStream in = // find yours > properties.load(in); > return (MyMessages) > Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] > { MyMessages.class }, > new GWTMessageProxy(properties)); > } > > } > > public class GWTMessageProxy implements InvocationHandler { > > private final Properties properties; > > public GWTMessageProxy(Properties properties) { > super(); > this.properties = properties; > } > > public Object invoke(Object proxy, Method method, Object[] args) > throws Throwable { > String property = > String.valueOf(properties.get(method.getName())); > if (args != null && args.length > 0) { > // we have a messages class... > return MessageFormat.format(property, args); > } > return property; > } > > } > > When you initialize your client side system, simply initialize your > messages with a client-side-only version that uses gwt localization. > Similarly, your tests probably need a different setup method, so just > initialise a custom class for that as well. It's kind of like manual > guice, but it doesn't have to be done that often so isn't a big deal. > > This pattern works for everything, so we use it for NumberFormats & > DateFormatting and all sorts of other code that need to be shared > between client, server, tests etc. > > If anyone has any better ideas please sing out! > > Joe > On Aug 17, 7:20 am, Casey <j.casey.one...@gmail.com> wrote: > > > Does anyone know if with Google Web Toolkit there is an easy way to > > reuse your client size localization files (constants and messages) in > > the server side code? I think in GWT 1.6 or 1.8 you could actually > > call the same GWT localization code on the server side that you called > > on the client side. I just upgraded from 1.6 to 2.0 and all of a > > sudden I'm receiving the following message: ERROR: GWT.create() is > > only usable in client code! That makes sense to me but there must be > > an easy way to reuse your Constant and Message files on the server. > > It's been awhile since I've opened this project but I'm pretty sure > > that this was working before. Thanks in advance. -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.