I have a little problem and no idea + grey hair.
I dont know much about gsp’s, groovy, grails etc. But here’s the situation:
I need to display an image if the number I get from mongodb is greater than 4.5, for example.
I tried many different stuff like that:
<g:if test="${profil.punkte >0.1}">
<img src="${resource(dir: 'images', file: '1_5.gif')}" alt="gesamtbewertung in sternen" >
</g:if>
<g:elseif test="${profil.punkte >1.49}">
<img src="${resource(dir: 'images', file: '2_5.gif')}" alt="gesamtbewertung in sternen" >
</g:elseif>
<g:elseif test="${profil.punkte >2.49}">
<img src="${resource(dir: 'images', file: '3_5.gif')}" alt="gesamtbewertung in sternen" >
</g:elseif>
<g:elseif test="${profil.punkte >3.49}">
<img src="${resource(dir: 'images', file: '4_5.gif')}" alt="gesamtbewertung in sternen" >
</g:elseif>
<g:elseif test="${profil.punkte >4.49}">
<img src="${resource(dir: 'images', file: '5_5.gif')}" alt="gesamtbewertung in sternen" >
</g:elseif>
I tried a lot of different syntaxes to solve this, but it just won´t work. In the version above it always shows 1_5.gif
The entry in the “profil.groovy” looks sth. Like:
class Profil {
ObjectId id
...
...
double punkte
}
And the entry in mongodb´s JSON looks like :
"punkte": 4.3,
I just need to type ${profil.punkte} and I get 4.3 rendered.
Hope you understand my problem even if my english is broken.
I will make a backflip on my laptop for solving!
Well, you need to make better conditions. Do you see that 4.3 is greater than 0.1? Then it always enters the first if and nothing else.
Add some limit in your conditions and it will work.