Reputation: 820
I have defined a custom jsr-303-Validator called @RequiredWhen
which is like @NotNull
but depending on some condition.
In JSF, whenever I annotate a managed bean property with @NotNull
a component like PrimeFaces <p:outputLabel for="that property">
, recognizes the property as required and marks it with an asterisk. Is it possible to implement or configure my custom Validator such that the asterisk is shown as well, if the condition in the @RequiredWhen
-annotation becomes true? Thanks a lot.
I'm using,
Upvotes: 0
Views: 612
Reputation: 820
As far as I can see by now the answer is no: it's not possible to show the asterix by configuring or implementing the custom validator. Looking at the sources of primefaces the check for @NotNull is hardcoded and there is no kind of callback to check for other annotations.
As a first workaround we added a new bean that checks an input field for our custom annotations, eg
<p:inputText id="test" value="#{uiController.data}"
required="#{ContextValidatorDelegate.isRequired('data')}"/>
But after some closer look we removed that delegate. The condition in our custom validator is dependend on properties that the user can modify in the same dialog than the property that is validated. So our validator really is some class level validator. And thus we cannot use the required-attribute, which is processed in validation phase. We need the complete user-input in our model bean. Only after the update model phase a class level validation is meaningful.
Upvotes: 0