Reputation: 142
So what I am trying to achieve is, that my default image from the resource library is used, whenever the value attribute couldn't reference a proper image (e.g. no image uploaded/no image in the database).
Just to visualize it:
The user hasn't provided a profile pic, so bean.icon
should be null
.
<o:graphicImage value="#{bean.icon}" dataURI="true" /> (null isn't allowed as return value)
Now I would like the graphicImage component to display the default instead, semantically spoken:
<o:graphicImage name="img/default.png" dataURI="true" />
Is it possible to achieve this in an elegant way, perhaps without the use of JavaScript?
Upvotes: 3
Views: 1314
Reputation: 1108732
Not via <o:graphicImage>
component. You could however achieve this in the bean with help of Faces#getResourceAsStream()
utility.
public InputStream getIcon() {
InputStream input = yourIconService.getIconAsInputStreamSomehow();
return (input != null) ? input : Faces.getResourceAsStream("/resources/img/default.png");
}
Upvotes: 4