如何有条件地隐藏h:outputLink?

时间:2012-11-08 14:39:14

标签: java jsf java-ee

如何根据支持bean中的布尔值隐藏h:ouputLink

对于禁用我会这样:

<h:commandButton disabled="#{backing.property}" />

但我怎么能完全隐藏?

1 个答案:

答案 0 :(得分:2)

使用:

<h:commandButton id="myComponent" rendered="#{backing.property}" />

对不起,我的错。您正在搜索h:outputLink。因为 h:outputLink h:commandButton 都派生自UIComponentBase,所以两个派生类都使用方法isRendered()并且您不需要包装在某种面板中使用commandLink。

<h:outputLink rendered="#{backing.property}" />

<强>更新

myComponent 将被“隐藏”,因为它不会被渲染。 不要渲染 myComponent 意味着您需要在围绕 myComponent 的UIComponent上进行更新(例如,使用ajax请求),如下所示:< / p>

<h:panelGrid id="myPanelGrid">
  ....
  <h:outputLink id="myComponent" rendered="#{backing.property}" />
  ....
<h:panelGrid>

<h:commandButton value="show" action="#{backing.setPropertyToTrueMethod}" update="myPanelGrid" />

参见API规范:JavaTM Platform, Enterprise Edition 6 API Specification

相关问题