如果在JSF中有条件的话

时间:2014-06-11 09:27:19

标签: java jsf jsf-2

我尝试应用渲染以检查JSF中是否有条件。 (参考:Conditionally displaying JSF components

这部分是我的JSF index.html

<p:commandButton value="Update Hidden Label" action="#{carForm.updateBool}" />
<h:outputText value="Text A" />
<h:outputText value=" Text B" rendered="#{carForm.booleanValue}" />

这是我的java类

private boolean booleanValue;

public boolean isBooleanValue() {
    return booleanValue;
}

public void setBooleanValue(final boolean booleanValue) {
    this.booleanValue = booleanValue;
}

public void updateBool() {
    booleanValue = true;
}

当我尝试点击“更新隐藏标签”时,它会将java类中的booleanValue更新为true,但是在index.html页面中“文本B”仍然没有出现。

1 个答案:

答案 0 :(得分:4)

您还需要使用<h:outputText value=" Text B" rendered="#{carForm.booleanValue}" />

更新页面片段

您可以使用<p:panel id="textPanel"></p:panel>并将代码放在那里。

update参数添加到p:commandButton,其值为textPanel,如update="textPanel"

<p:panel id="textPanel">
  <p:commandButton value="Update Hidden Label" action="#{carForm.updateBool}" update="textPanel" />
  <h:outputText value="Text A" />
  <h:outputText value=" Text B" rendered="#{carForm.booleanValue}" />
</p:panel>