Thank you for your help some hours ago! Now, I face a new problem... :(
The field, which should be required if a special radio button is selected cannot change back to "required=false" if the radio button is changed again. The error message, that the field cannot be empty is shown.
Here is my code:
Bean method:
public void required(AjaxBehaviorEvent event) {
if (test.isRadioButton()) {
requirement = true;
} else {
requirement = false;
}
}
----
xhtml:
<h:panelGroup id="buttons" layout="block" styleClass="buttonAbstand" >
<p:selectOneRadio id="radio" value="#{bean.test.radioButton}" required="true" requiredMessage="#{i18n['error.response']}" >
<f:selectItem itemValue="#{true}" itemLabel="#{i18n['common.ja']}" />
<f:selectItem itemValue="#{false}" itemLabel="#{i18n['common.nein']}" />
<f:ajax execute="panel1" listener="#{bean.required}" render="panel1" />
</p:selectOneRadio>
</h:panelGroup>
<h:panelGroup id="panel1" >
<h:panelGroup rendered="#{bean.requirement}" >
<br />
<h:outputLabel value="#{i18n['input']}" styleClass="labelFont" />
<br />
<p:inputText id="inputText" value="#{bean.test.input}" styleClass="text" required="#{bean.requirement}" requiredMessage="#{i18n['error.input']}" />
</h:panelGroup>
</h:panelGroup>
My bean has these annotations: @Service @ViewScoped @Getter @Setter.
I would be very glad if you could help me! Best wishes!