Reputation: 35
I tried apply rendered in order to check for if else conditional in JSF. (ref: Conditionally displaying JSF components)
This part is my 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}" />
This is my java class
private boolean booleanValue;
public boolean isBooleanValue() {
return booleanValue;
}
public void setBooleanValue(final boolean booleanValue) {
this.booleanValue = booleanValue;
}
public void updateBool() {
booleanValue = true;
}
when I tried click on "Update Hidden Label", it would update the booleanValue in java class to true, however in index.html page "Text B" is still not appear yet.
Upvotes: 1
Views: 1017
Reputation: 2580
Also you need to update page fragment with <h:outputText value=" Text B" rendered="#{carForm.booleanValue}" />
You can use <p:panel id="textPanel"></p:panel>
and put your code there.
And add update
parameter to p:commandButton
with value textPanel
, like this 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>
Upvotes: 4