On page I have checkbox which enables/disables h:inputText and h:selectOneMenu. That works fine until I refresh the page. Value of checkbox is probably cached by browser.
So, when the checkbox was set on "true" after refresh both controls are enabled. selectOneMenu is rendered corresponding to value set in init() method, but selectBooleanCheckbox and inputText isn't. How can I fix that? I use Firefox browser.
Backing bean is simple, one property and one method - init in which value is set to false.
@ManagedBean(name="newBean")
@ViewScoped
public class NewBean implements Serializable {
private boolean booleanValue;
public NewBean() {
}
public void init()
{
booleanValue = true;
}
public boolean isBooleanValue() {
return booleanValue;
}
public void setBooleanValue(boolean booleanValue) {
this.booleanValue = booleanValue;
}
}
Page source:
<h:body>
<f:metadata>
<f:viewAction action="#{newBean.init()}"></f:viewAction>
</f:metadata>
<h:form>
<h:outputText value="#{newBean.booleanValue}"></h:outputText>
<br/>
<h:selectBooleanCheckbox value="#{newBean.booleanValue}" id="selected">
<f:ajax event="change"
render="enabledInput disabledInput enabledMenu"></f:ajax>
</h:selectBooleanCheckbox>
<br/>
<h:inputText disabled="#{newBean.booleanValue}" id="enabledInput"></h:inputText><br/>
<h:selectOneMenu disabled="#{!newBean.booleanValue}" id="enabledMenu">
<f:ajax></f:ajax>
</h:selectOneMenu>
</h:form>
</h:body>
EDIT: Added some screenshots so it will be easier to understand the problem.
Correct: Page opened by user (checkbox is checked, and it corresponds to bean value, textbox is disabled, menu is enabled):
Correct: User unchecked checkbox (checkbox is unchecked, value on bean is false too, textbox is enabled, menu is disabled):
ISSUE: after unchecking user refreshed page. Value on bean is true, but checkbox is still unchecked. Also, textbox and menu are BOTH enabled.