0

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):

  1. 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.

  2. If no value is provided, no validation occurs, and page is allowed to submit

Use Case (Glassfish):

  1. Same as above

  2. 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.

Community
  • 1
  • 1
Mickelback
  • 351
  • 2
  • 5
  • 16

1 Answers1

1

I had a very similar issue a few days ago and I assume that the property phoneArea might be an Integer or Long. If so, you may take a look at this topic and additionally at this one.

Community
  • 1
  • 1
Markus Ratzer
  • 1,292
  • 3
  • 19
  • 29
  • Thank you MarkusR for your time on this, unfortunately all my fields are bound to String values. Also, I'm not sure (still looking into it), but the links you provided seem to be issues if I was trying to target Tomcat. We are trying to migrate to Glassfish and from what I read, @BalusC seemed to indicate the specific issue referenced was only an issue with Tomcat and not Glassfish. Please let me know, however; if I have misinterpreted what you referenced. Thank you again! – Mickelback Oct 02 '12 at 14:56
  • Using the second reference you, [provided](http://stackoverflow.com/questions/7545231/notnull-notblank-and-notempty-bean-validation-does-not-work-in-jsf/7548821#7548821) ,enabled me to get over this problem. I added the `javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL` to the web.xml and now all is functioning as desired. Thank you! – Mickelback Oct 02 '12 at 16:32
  • this seemed to work at first, however; if I add the above to my web.xml -- any component that has the required="true" attribute will not show the validation error message. The page will not post, but still user is left wondering why because no message displays. – Mickelback Oct 26 '12 at 16:51