I'm experiencing what I think is odd behavior with the JSF validation between Tomcat and Glassfish. Previously we were using Tomcat, but now have requirements to run a full Java EE App Server.
During testing, I noticed when submitting empty fields to the server, that simply have a length validator and no required attribute, Glassfish is outputting the validation message whereas, Tomcat would simply skip the validation on these elements.
If a value is submitted and fails validation everything works fine, it is simply when no value is entered and the page is submitted.
Environment Specifics
- JSF Mojarra 2.1.12
- Richfaces 4.1
- Target server Glassfis 3.1.2
- Moving from Tomcat 7.0.27
Here is a snippet of code that contains the described behavior:
<h:inputText id="phoneAreaCode"
maxlength="3"
size="2"
value="#{bean.phoneArea}"
style="margin-left: 8px;">
<f:validateLength minimum="3"/>
<f:validator validatorId="phoneValidator"/>
<a4j:ajax/>
</h:inputText>
Use Case (Tomcat):
If a value is provided, validation occurs. If value passes validation, page is allowed to submit, if it fails, error message is outputted to page.
If no value is provided, no validation occurs, and page is allowed to submit
Use Case (Glassfish):
Same as above
If no value is provided, validation still occurs, and obviously fails.
I am seeing this behavior for custom validators via <f:validator/>
tags as well as the built in ones like <f:validateLength/>
.
No code difference, just the server the code is running on. I've searched Google and I'm not really finding anything to help. Am I not understanding something about validation? Do you see anything wrong?
This Stackoverflow question sounds like the same issue, I just don't see the solution to prevent my environment from behaving in this manner or how to disable the validation when the field is not required.
Thank you to anyone for helping me out on this.