jsf 2 - How to use if, else condition in jsf to display image -


i have condition have enrollment form in if userid 0 should show dummy image , when edit user update, check if userid not equal 0 display image corresponding userid.

i used jstl inside jsf page. tries go else loop showing image. functionality working fine. thing can't display dummy image when visit page first. here s code.:

<c:if test="${'#{user.userid}' == '0'}">   <a href="images/thumb_02.jpg" target="_blank" ></a>   <img src="images/thumb_02.jpg" /> </c:if> <c:otherwise>   <a href="/displayblobexample?userid=#{user.userid}" target="_blank"</a>   <img src="/displayblobexample?userid=#{user.userid}" /> </c:otherwise> 

can use jstl tag or can using jsf?

it illegal nest el expressions: should inline them. using jstl valid in situation. correcting mistake, you'll make code working:

<c:if test="#{not empty user or user.userid eq 0}">     <a href="images/thumb_02.jpg" target="_blank" ></a>     <img src="images/thumb_02.jpg" /> </c:if> <c:if test="#{empty user or user.userid eq 0}">     <a href="/displayblobexample?userid=#{user.userid}" target="_blank"></a>     <img src="/displayblobexample?userid=#{user.userid}" /> </c:if> 

another solution specify conditions want inside el of 1 element. though heavier , less readable, here is:

<a href="#{not empty user or user.userid eq 0 ? '/images/thumb_02.jpg' : '/displayblobexample?userid='}#{not empty user or user.userid eq 0 ? '' : user.userid}" target="_blank"></a> <img src="#{not empty user or user.userid eq 0 ? '/images/thumb_02.jpg' : '/displayblobexample?userid='}#{not empty user or user.userid eq 0 ? '' : user.userid}" target="_blank"></img> 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -