Reputation: 147
I have my database whit a BLOB field named 'avatar' in which I store the user's photo. This field is represented in my JPA entity as a byte[]. I want to render the 'avatar' element only if the array has a positive length, but i get the next exception from javax.servlet.FilterChain.doFilter() :
"Exception: Method length not found"
This is the code:
<o:graphicImage id="avatar"
value="#{loginView.user.avatar}"
dataURI="true"
rendered="#{loginView.user.avatar.length()>0}"
/>
If I check the length from the backing bean, returning a Boolean to the EL, it works and renders the image, but I need to preserve the backing code unaltered, that's why I need to do the checking from my xhtml. Thanks.
edit: rendered="#{not empty loginView.user.avatar}" is not working, that's why I had to move to another option.
Upvotes: 0
Views: 173
Reputation: 512
Try using JSTL. Taglib namespace:
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
Usage:
<o:graphicImage id="avatar"
value="#{loginView.user.avatar}"
dataURI="true"
rendered="#{fn:length(loginView.user.avatar) > 0}"/>
Upvotes: 1
Reputation: 517
Length is not a method but property of array. Try to make a method inside loginView bean which will return something like this.
public boolean isAvatarLoaded() {
return this.user.avatar.length > 0;
}
<o:graphicImage id="avatar"
value="#{loginView.user.avatar}"
dataURI="true"
rendered="#{loginView.isAvatarLoaded()}"
/>
Upvotes: 0