I’m trying to display just one for two Fields that are required.
At the moment there are two error messages if both fields are empty. I want to achieve that there is just one message if both or just one field is empty.
The code looks like this:
<x:inputText
value="#{bean.proxyUrl}"
id="idProxyUrl"
required="true"
/>
<x:outputText value=":" />
<x:inputText
value="#{bean.proxyPort}"
id="idProxyPort"
required="true"
/>
<x:message for="idProxyUrl" errorClass="errorMessage" style="margin-left: 10px;" />
<x:message for="idProxyPort" errorClass="errorMessage" style="margin-left: 10px;" />
What can I do about it, that I only get one message no matter if one or both of the fields are empty.
You can specify a special validator for the second component that checks the SubmittedValue of the first one. I did something similar for a PasswordValidator that checked the corresponding Confirm Password field.
The reason why you must check for the Submitted Value of the other component is because the validator is called during the Process Validations phase of the lifecycle. None of the Submitted Values are applied until after this phase has been completed and every submitted value has passed validation.