Usind the onerror approach as mentioned in my post above is not working
when I want to use uibinder together with ImageResource ClientBundle.
The following declaration in my ui.xml
<img class="{style.image}" src="{itemImage}" alt="" onerror="this.src={res.
default_image.getSafeUri.asString}" />
produces the following error output if I try to compile with super dev mode.
Generating method body for html1() [ERROR] Template variables in javascript
context are not supported: <div class='{0}'><img alt='' class='{1}'
onerror='{2} [ERROR] Errors in
'gen/xx/xxx/client/views/cells/ItemCellWithUiBinder_MyUiRendererImpl.java'
[ERROR] Line 23: Failed to resolve
'xx.xxx.client.views.cells.ItemCellWithUiBinder_MyUiRendererImpl.Template' via
deferred binding
I also tried (added "this.src='" at the beginning of the String and a "'"
at the end of the String.
<ui:with field='defaultItemImage' type='java.lang.String'/>
....
onerror="{defaultItemImage}"
which ended also with an compile error. Is there no support/way to fill
onerror in uibinder with dynamic code / or an ImageResource?
Am Donnerstag, 8. Januar 2015 10:12:45 UTC+1 schrieb marian lux:
>
> At the beginning it was not clear for me that this is a mgwt - topic. But
> you are right.
>
>
> Adding a DomHandler which is listening on Error Events does not work. The
> Window.alert-Message will be never reached.
> cellList.addDomHandler(new ErrorHandler() {
>
> @Override
> public void onError(ErrorEvent event) {
> Window.alert("error occurred!");
> }
> }, ErrorEvent.getType());
>
> Inspired by http://www.stillnetstudios.com/onerror-img-image-tag/ I found
> an other way. If I add in my uibinder.ui.xml:
> <img class="{style.image}" src="{itemImage}" alt="" onerror="this.src='
> http://alternative/image.jpg'" />
> It works but it seems not very elegant. E.g.: loop if onerror-image not
> available/reachable. It would be nice to handle the onerror in gwt-code and
> not in the declaration of the template. The next thing I need to test with
> this solution is to display an Image-Resource from ClientBundle.
>
> Am Mittwoch, 7. Januar 2015 18:27:32 UTC+1 schrieb Jens:
>>
>> A bit unfortunate that GWT has a CellList and MGWT has a CellList and
>> both are totally different. Maybe you should ask this on a MGWT mailing
>> list?
>>
>> But given that MGWT CellList is a Widget you can add any event handler to
>> it using addDomHandler(). I am not sure about the error event but I would
>> try adding a ErrorEvent/ErrorHandler to the CellList. If it really triggers
>> then you should be able to figure out the <img> element and change its src
>> attribute if loading has failed.
>>
>> And yes you need an <img> element because no event exists that tells you
>> if a CSS background image has been loaded or not.
>>
>> -- J.
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.