JSF 2.1.X validation behaves differently on Glassfish 3.1.2 vs. Tomcat 6 & 7

狂风中的少年 提交于 2019-12-12 04:48:45

问题


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.


回答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.



来源:https://stackoverflow.com/questions/12678784/jsf-2-1-x-validation-behaves-differently-on-glassfish-3-1-2-vs-tomcat-6-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!