Reputation: 17873
I'd like to conditionally render attributes of a plain HTML <div>
element. I tried as below using <c:if>
:
<ui:composition
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<div data-product-id="#{ID}"
<c:if test="${not empty testvalue1}">
data-test1-for="#{testvalue1}"
</c:if>
<c:if test="${not empty testvalue2}">
data-test2-for="#{testvalue1}"
</c:if>
>
div content
</div>
</ui:composition>
However, it produced a Facelet exception:
com.sun.facelets.FaceletException: Error Parsing /assets/template/module/container/product/product-marker.xhtml: Error Traced[line: 9] Element type "div" must be followed by either attribute specifications, ">" or "/>"
How can I conditionally render attributes of a plain HTML <div>
element?
Upvotes: 1
Views: 1044
Reputation: 655
You don't need those if statements. If the values are empty, attributes won't be rendered on the page automatically.
Upvotes: 1