jsf 2 - <c:if><c:otherwise> does not work, both conditions evaluate like true -
i trying toggle between 2 different command buttons depending on whether list contains given item id:
<c:if test="#{roomservicemanagerbean.holdinghotelvilla.contains(hotel.hotelvillaid)}"> <p:commandbutton ajax="true" id="commanddeactivate" update=":roomserviceform:hoteltable,:roomserviceform:msgs" actionlistener="#{roomservicemanagerbean.deactivateserviceforhotel(hotel.hotelvillaid)}" icon="ui-icon-radio-off" type="submit" value="remove service"> <f:param name="roomserviceid" value="#{roomservicemanagerbean.roomserviceid}" /> </p:commandbutton> </c:if> <c:otherwise> <p:commandbutton id="commandactivate" update=":roomserviceform:hoteltable,:roomserviceform:msgs" actionlistener="#{roomservicemanagerbean.activateserviceforhotel(hotel.hotelvillaid)}" icon="ui-icon-radio-on" type="submit" value="provide service"> <f:param name="roomserviceid" value="#{roomservicemanagerbean.roomserviceid}" /> </p:commandbutton> </c:otherwise>
however, fails , both buttons appear. how caused , how can solve it?
the <c:if>
in construct fail if #{hotel}
not available during view build time during view render time (e.g. because it's definied <p:datatable var>
). <c:otherwise>
displaced here. belongs <c:choose><c:when>
. technically, should using <c:if>
instead negation in test
. or, should replacing first <c:if>
<c:when>
, wrap whole thing in <c:choose>
. still fail if #{hotel}
not available during view build time.
just use jsf component's rendered
attribute instead.
<p:commandbutton ... rendered="#{roomservicemanagerbean.holdinghotelvilla.contains(hotel.hotelvillaid)}"> ... </p:commandbutton> <p:commandbutton ... rendered="#{not roomservicemanagerbean.holdinghotelvilla.contains(hotel.hotelvillaid)}"> ... </p:commandbutton>
Comments
Post a Comment