<c:if> <c:otherwise>不起作用,两个条件的评估都是真的</c:otherwise> </c:if>

时间:2013-09-24 21:14:07

标签: jsf-2 primefaces jstl

我试图在两个不同的命令按钮之间切换,具体取决于列表是否包含给定的项目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>

然而,它失败并且两个按钮都出现了。这是怎么造成的,我该如何解决?

1 个答案:

答案 0 :(得分:1)

如果<c:if>在视图构建期间不可用,则此#{hotel}中的<p:dataTable var>将失败,但仅在视图渲染时间内(例如因为它被定义为<c:otherwise>)。 <c:choose><c:when>完全取代了这里。它属于<c:if>。从技术上讲,您应该使用test代替<c:if>中的否定。或者,您应该用<c:when>替换第一个<c:choose>并将整个内容包装在#{hotel}中。但是,如果在视图构建期间rendered不可用,那么仍然会失败。

只需使用JSF组件的<p:commandButton ... rendered="#{roomServiceManagerBean.holdinghotelvilla.contains(hotel.hotelvillaId)}"> ... </p:commandButton> <p:commandButton ... rendered="#{not roomServiceManagerBean.holdinghotelvilla.contains(hotel.hotelvillaId)}"> ... </p:commandButton> 属性。

{{1}}

另见:

相关问题