Reputation: 14003
I thought this would be an automatic:
<rich:tooltip value="Download (#{doc.size div 1024 + 1} KB)" />
I need to calculate the number of KB a file has for downloading (size is integral). In regular Java code the same calculation would truncate the fractional part and return that remaining integer. In JSF EL however, there's no truncating division, so the division return a float.
How is it done in EL anyway - that is without introducing a bean method that does the job?
Upvotes: 1
Views: 1277
Reputation: 1109322
You can use fn:split()
to get rid of the fraction.
<ui:param name="size" value="#{fn:split(doc.size / 1024, '.')[0]}" />
<rich:tooltip value="Download (#{size + 1} KB)" />
Be cautious: it's locale dependent. On some locales it's a comma ,
. I'd rather create/use an EL function for the job, something like as OmniFaces of:formatBytes()
is doing.
<rich:tooltip value="Download (#{of:formatBytes(doc.size)})" />
Upvotes: 2