Re: Simple UiBinder question about

2013-06-26 Thread Ivan Bahdanau
Here is kind-a workaraound that worked for me:

in cell widget declarative ui add following:


...

...





=

In the code then:
=
...
interface MyUiRenderer extends UiRenderer {
... 
void render(SafeHtmlBuilder sb, ... ,SafeHtml loadingIcon);
...
}

@Override
public void render(Context context, ..., SafeHtmlBuilder sb) {
if (value == null) {
return;
}
ImageResourceRenderer imageRenderer = new ImageResourceRenderer();
renderer.render(sb, ... ,imageRenderer.render(images.checkOk()));
}

=

On Monday, February 8, 2010 1:49:22 AM UTC-8, cpm wrote:
>
> I'm another one finding that the resource="{res.myImage}" just won't
> work.
>
> My findings are that I can have just  in
> the file along with an @sprite .logo { gwt-image: "myImage"; } and as
> long as I have an image file called myImage.png in the same package/
> directory it'll work.
> You don't seem to need a resource="" or src="" on the ui:image tag at
> all - the field attribute is the name of the image it'll look for
> unless you add a src attribute. This would explain why emerix was
> getting an "No com.google.gwt.resources.client.ClientBundle $Source
> annotation and no resources found with default extensions " error
> with:
>
> 
>
> It's just ignoring the resource attribute and looking for a logo.png
> file instead.
>
> The src attribute seems to work like the @Source annotation you would
> put in a ResourceBundle, such as:
>
> @Source("myLogo.png")
> ImageResource logo();
>
> I would expect this to be the same as:
>
> 
>
>
> The same seems to apply then when you try to use  field="logo" resource="{res.myLogo}" />
> The resource attribute is ignored and its still looking for a logo.png
> in the current directory and flagging an error that no Source
> annotation has been given.
> What you need to do to get the resource atrribute to work, I've no
> idea, but it would be a neater solution if it did work.
>
> but I got the error :
>
> On Jan 18, 5:12 pm, emerix  wrote:
> > Hi,
> >
> > I'm also still looking for some documentation on this  tag.
> > (and the other tags also : ui:data, ui:attribute, ...)
> >
> > Do anyone know how to put absolute path in the src attribute ?
> >  > ui:image>
> > doesn't work :/
> >
> > Using relative path works but I have to change it every time I copy
> > the code to another widget :/
> >
> > ++emerix
> >
> > On Jan 17, 6:05 pm, Nico  wrote:
> >
> > > Thanks emerix for the src="" tips. It helped me a lot.
> >
> > > I have the same problem when I use resource="{res.myImage}" ...
> >
> > > I have declared the  targeting the right Resource
> > > class but I always have an error that says : No
> > > com.google.gwt.resources.client.ClientBundle$Source annotation and no
> > > resources found with default extensions
> >
> > > However, I don't know where to find doc about  tag. Where
> > > did you find that there was a src or a resource attribute ? directly
> > > in the source code ?
> > > Thanks a lot.
> >
> > > Nicolas
> >
> > > On 12 jan, 17:24, Chris Ramsdale  wrote:
> >
> > > > Do you have the following in your ui.xml file:
> >
> > > > 
> >
> > > > ...where 'com.google.gwt.sandbox.client.Resources' is replaced with 
> your
> > > > resources class.
> >
> > > > On Thu, Jan 7, 2010 at 5:24 AM, emerix  wrote:
> > > > > Hello,
> >
> > > > > I tried using relative paths for the resource property :
> > > > >  resource='../resources/my_logo.png'>
> >
> > > > > but I got the error : No 
> com.google.gwt.resources.client.ClientBundle
> > > > > $Source annotation and no resources found with default extensions
> >
> > > > > if I use the src property, everything is ok :
> > > > > 
> >
> > > > > hope someone find this useful :)
> >
> > > > > However what I really wanted is using your 2nd solution :
> > > > > 
> > > > > but when I load the page I also get the error : No
> > > > > com.google.gwt.resources.client.ClientBundle$Source annotation and 
> no
> > > > > resources found with default extensions
> >
> > > > > am I missing something ?
> >
> > > > > thanks a lot :)
> >
> > > > > ++emerix
> >
> > > > > On Jan 4, 11:15 pm, Chris Ramsdale  wrote:
> > > > > > One option would be to use relative paths within the  
> element.
> > > > > For
> > > > > > example:
> >
> > > > > >  resource='../resources/my_logo.png'>
> >
> > > > > > Another option would be to use , get a hold of the 
> ClientBundle,
> > > > > > and reference an image within it.
> >
> > > > > > public interface Resources extends ClientBundle {
> > > > > >   @Source("com/google/gwt/sandbox/resources/my_logo.png")
> > > > > >   ImageResource logo();
> >
> > > > > > }
> >
> > > > > > 
> > > > > >   ...
> > > > > >type='com.google.gwt.sandbox.client.Resources'/>
> > > > > >   
> > > > > >   ...
> > > > > > 
> >
> > > > > > Underscores within the filename are completely valid (the above 
> examples
> > > > > > compile and run w/o issue).
> >
> > > > > > On T

GWT localization(i18n): make possible read on server side com.google.gwt.i18n.client.Messages (using spring on server side)

2011-10-05 Thread Ivan Bahdanau
*Problem: *
Required ability to have access to GWT client 
com.google.gwt.i18n.client.Messages files on server side(e.g. inside 
Servlet).
*Problem reason: *
In my case I needed to generate the PDF representation of the web page + 
save some string values in DB(when someone posts comment).
*Desired behaviour*:
Have a single MessageResource provider that can be executed from both server 
side and from client side:

*Solution:
*
   
   1. First of all *make sure that all GWT message resources are generated 
   from *.properties file via com.google.gwt.i18n.tools.I18NSync tool*(or 
   you have to synchronise i18n .properties files with GWT message interfaces 
   all the times). Otherwise, if you just using interfaces without using 
   *.properties files, this approach will not work.
   2. Now, let's *educate the server how to read GWT i18n *.properties*:
  1. I am using spring framework as server side, so in this example we 
  will educate Spring where the GWT's i18n *.properties are stored in the 
app:
   
  
  
  classpath:messages
  classpath:error_messages
  
  
classpath:/blabla/project/client/resources/i18n/messages/GlobalRes
  
  
  
  
  the classpath:/blabla/project/client/resources/i18n/messages/GlobalRes 
  is full path to GlobalRes.properties file. Make sure you include this 
file 
  in classpath when yo compile your project.
  2. Basically, after telling spring 
  ReloadableResourceBundleMessageSource where to take the resources is 
pretty 
  enough to have GWT messages being accessed on server side, by just 
injecting 
  messageSource into any place on server and using 
  messagesCourse.getMessage("messageCode",args[],locale). But this is not 
what 
  we want to achieve. The aim is to have the same message resource provider 
  that can be executed on server and on client side the same way.
  3. So next, let's just create this Messages Provider that can be 
   executed on both client and on server side:
   public class MessageResourceProvider {
   
   public static GlobalRes GLOBAL_RES;
   public static GlobalRes SERVER_GLOBAL_RES;
   
   static {
   try {
   GLOBAL_RES = GWT.create(GlobalRes.class);
   } catch (Exception e) {
   
   }
   }
   
   public static GlobalRes getGlobalRes() {
   if (GLOBAL_RES != null) {
   return GLOBAL_RES;
   } else {
   return SERVER_GLOBAL_RES;
   }
   }
   }
   
   First of all, make sure that MessageResourceProvider is stored under *.*
   client.** package, so GWT client side will be able to access it. So here 
   we have two instances for providing resources: one for server part, the 
   other one for client side. With client side everything is clear: we just try 
   to call GWT.create(GlobalRes.class) in static block and if it's successfully 
   executed(which actually means it executed on client side) then the 
   getGlobalResources will return client version of GlobalRes.
   But what about SERVER_GLOBAL_RES? Where should it come from? Obviously - 
   it should come from server.
   4. Ok, let's *tell server part to how inject SERVER_GLOBAL_RES into 
   MessageResourceProvider wher the server starts*.
   in order to do that I just added listener in my* web.xml* 
 
   
   org.kuali.lum.cmi.server.util.CmiServletListener
   
  
   so application will call this listener at startup time.
   the listener code is very simple: 
   public class CmiServletListener implements ServletContextListener {
   @Override
   public void contextInitialized(ServletContextEvent sce) {
   ServerMessageResourceFactory serverMessageResourceFactory = 
   (ServerMessageResourceFactory) 
   
WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()).getBean("serverMessageResourceFactory");
   MessageResourceProvider.SERVER_GLOBAL_RES = 
   serverMessageResourceFactory.getGlobalRes();
   }
   
   @Override
   public void contextDestroyed(ServletContextEvent sce) {
   
   }
   }
   As you see at startup time I just set MessageResourceProvider's 
   SERVER_GLOBAL_RES which I take from 
   serverMessageResourceFactory.getGlobalRes().
   5. So this is almost it, except I haven't described the most tricky and 
   interesting part: *how the serverMessageResourceFactory.getGlobalRes() 
   will return the com.google.gwt.i18n.client.Messages resources instance that 
   can de executed from server side and why hadn't we use messageResources, 
   that we've created at 2nd step?:
   *The answer is below: 
   public class ServerMessageResourceFactory {
   
   InvocationHandler handler = new InvocationHandler() {
   @Override
   public Object invoke(Object proxy, Method method, Object[]