0
votes

I have a p:inputText whose value in autogenerated component of PrimeFaces and I have to set required="true", the validation doesn't work when Disabled is true. here is my code:

<p:inputText id="depCode" disabled="true" required="true"
value="#{bean.depCode}"
style="width:100%"
requiredMessage="Please set a reference generator"
/>

Any suggestions please

1
Why do you need to validate a disabled input component after all? And if the sole purpose of this input component is to merely show a text value which is not be edited - should not be edited, then you should avoid using this input component and choose another non-editable component like <h:outputText>.Tiny

1 Answers

6
votes

You can't validate disabled or readonly form element using PF core ajax. For your need, I recommend you, if you have to have you inputText disabled, to use an h:inputHidden that tracks value of your p:inputText. And it is the h:inputHidden that is going do be validated instead.

<p:inputText id="depCode" disabled="true"  value="#{bean.depCode}" style="width:100%" />

<h:inputHidden id="depCodeTracker" required="true" value="#{bean.depCode}" requiredMessage="Please set a reference generator" />