I have the following code:
<h:form>
<h:inputText id="inputField" value="#{bean.myProperty}">
<f:validateLongRange
minimum="#{bean.minimum}"
maximum="#{bean.maximum}"/>
</h:inputText>
<h:commandButton id="submit" value="Submit" >
<f:ajax execute="inputField" render="outputField errors" />
</h:commandButton>
<h:outputText id="outputField" value="#{bean.myPropertyFormatted}"/>
<h:message id="errors" for="inputField"/>
</h:form>
When validation fails on the inputText, I would like to remove/hide the outputText from the user. What is the most elegant and future-refactoring-proof way to do this?
I tried setting the attribute rendered="#{!facesContext.validationFailed}"
on the outputText element, but that only determines whether or not the outputText element is RE-rendered, as opposed to leaving the old text unchanged. However, when the validateLongRange validation fails, I want to completely remove/hide the outputText from the user, since the user will be seing the validation error message and is not interested in seing an old output message based on a previous, valid input which is still the value stored in the bean.
rendered
doesn't do the job. If EL inside it returns falseoutputText
element will not be rendered, which means you will not have HTML of that element in browser at all. Isn't that what you need? - partlovoutputText
just stays the same, unchanged. I want it to disappear instead. If I invert the EL output (without the "!"), it's easier to see what's going on. Withrendered="#{facesContext.validationFailed}"
I don't get any update on theoutputText
for valid values, but I get an update as soon as I give an invalid value which results in a validation error. i.e. upon validation error I see the last valid value I entered before entering an invalid value. - Student