问题
<a4j:outputPanel id="tapalSectionSendToPanel" ajaxsingle="true">
<h:inputText id="sendToId1" value="#{MainBean.SectionBean.sendTo}"
class="createresizedTextbox"
required="true" requiredMessage="#{msg.labl_required}"
disabled="true" />
<h:message for="sendToId1" style="color:red" />
</a4j:outputPanel>
i need to validate textbox for empty validation and should show required when i click button without entering any value in textbox. It works fine without disabled="true"
. Whats the alternative for my requirement.
回答1:
disabled="true"
disables the input (so it's skipped when the form is submitted), if you don't want the user to type in it use readonly="readonly"
回答2:
First, required
and disabled
don't go well together, because they are mutually exclusive as per the JSF Spec:
- required: Flag indicating that the user is required to provide a submitted value for this input component.
- disabled: Flag indicating that this element must never receive focus or be included in a subsequent submit.
Like I said in the comments, you can just display a message when the user tries to submit the form without selecting a node:
<h:inputText id="sendToId1" value="#{MainBean.SectionBean.sendTo}"
styleClass="createresizedTextbox" required="true" readonly="true" />
<h:message for="sendToId1" value="#{msg.labl_required}"
rendered="#{facesContext.postback and facesContext.validationFailed}" />
As an alternative you can just display a text anywhere in your markup:
<h:outputText value="#{msg.labl_required}"
rendered="#{empty MainBean.SectionBean.sendTo}" />
来源:https://stackoverflow.com/questions/17945126/why-does-required-true-not-fail-validation-when-disabled-true-is-specified