You need to send an ajax (partial) request instead of a full request. You can use <f:ajax>
inside the command component for this. It has a render
attribute taking a spaceseparated collection of client IDs which needs to be updated. Then, the input component's rendered
attribute must be a dynamic value expression referring a bean property instead of a hardcoded value of false
. E.g. a boolean
property. You just have to set that property to true
then. You don't and shouldn't need to bind the whole component to the bean. That's poor practice.
All in all, this should do:
<h:commandButton id="show" value="Show" action="#{bean.setShow(true)}">
<f:ajax render="group" />
</h:commandButton>
<h:panelGroup id="group">
<h:inputText id="username" rendered="#{bean.show}" />
</h:panelGroup>
with (assuming JSF 2.2, with @ViewScoped
for reasons mentioned here)
import javax.inject.Named;
import javax.faces.view.ViewScoped;
@Named
@ViewScoped
public class Bean {
private boolean show;
public boolean isShow() {
return show;
}
public void setShow(boolean show) {
this.show = show;
}
}