I need to write a link with an image inside. Instead of explaining, here is the code that I have now:
<c:if test="${userSession.loggedUser eq null and company.image != null}"> <a onclick="${rich:component('loginPanel')}.show()"> <img src="/download.do?hash=#{company.image.hash}" /> </a> </c:if> <c:if test="${userSession.loggedUser eq null and company.image == null}"> <a onclick="${rich:component('loginPanel')}.show()"> <img src="${request.contextPath}/img/icons/logo_default.jpg" /> </a> </c:if> <c:if test="${userSession.loggedUser ne null and company.image != null}"> <a href="company.xhtml?${company.name}"> <img src="/download.do?hash=#{company.image.hash}" /> </a> </c:if> <c:if test="#{userSession.loggedUser ne null and company.image == null}"> <a href="company.xhtml?${company.name}"> <img src="${request.contextPath}/img/icons/logo_default.jpg" /> </a> </c:if>
This code looks awful - there are two exact links with two exact images, but are combined in all possible combinations. Is there a better way? Is there a way to avoid c: if - did he create the tables?
Update : Bojo suggests: You can replace <c:if and <a with <h:outputLink rendered="#{..}" . In addition, I do not see any other optimization.
But that will not work. This does not display correctly:
<a href=> <h:outputLink rendered="#{..} <h:outputLink rendered="
(image is out of bounds)
It does a fine:
<h:outputLink value=> <h:outputLink rendered="#{..} <h:outputLink rendered="
but it always adds href, and in two cases I don't want href when rendering.
Update2 : I also combined them 2 to 2:
<c:if> <a href...> <c:if><img...></c:if> <c:if><img...></c:if> </a> </c:if> <c:if> <a onclick...> <c:if><img...></c:if> <c:if><img...></c:if> </a> </c:if>
It also doesn't display correctly - <a does not surround images for some crazy reason.
source share