Monday, January 5, 2015

SafeHtmlTemplate display alternative (backgorund- or cell-) image inside (mgwt)CellList-Item if image not available

Today I am rendering my mgwt CellList with the following Template and (rendering) method:

public interface Template extends SafeHtmlTemplates{
 
@SafeHtmlTemplates.Template("<div style='{0}' class='{2}'>'{1}'</div>")
 
SafeHtml content(SafeStyles dynamicBackgroundImage, String cellContents,
 
String cssMyCell);
 
}

public void render(SafeHtmlBuilder safeHtmlBuilder, ActivityItem model) {
 
ArrayList<String> images = model.getImages();
 
 
SafeStylesBuilder safeStylesBuilder = new SafeStylesBuilder();
 safeStylesBuilder
.trustedBackgroundImage("url('" + images.get(0) + "')");
 
 
String cssMyCell = SingletonClientResources.getInstance().getCssResources().getActivityItemCellCss().activityItemCell();
 
 
SafeHtml content = TEMPLATE.content(safeStylesBuilder.toSafeStyles(),model.getTitle(), cssMyCell);
 safeHtmlBuilder
.append(content);
 
}

Sometimes the Image URL #1 (images.get(0)) is not valid/available and there should appear a default Image. So Chrome dev console tells me e.g: 
GET http://xyz.jpg 403 (Access Denied)

If this occurs, I want to display an alternative Image e.g. from my ClientBundle.
How can I handle this in an elegant way? 
(I know I could test all URLs by adding an Image Widget and listening for ErrorHandler. Also I don't want to check the URLs on Server side because the server is not in my influence)

THX
Marian

--
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 google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment