JSF 2.1.X验证在Glassfish 3.1.2与Tomcat 6& 7 [英] JSF 2.1.X validation behaves differently on Glassfish 3.1.2 vs. Tomcat 6 & 7

查看:105
本文介绍了JSF 2.1.X验证在Glassfish 3.1.2与Tomcat 6& 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在经历Tomcat和Glassfish之间JSF验证的奇怪行为。以前我们使用Tomcat,但现在需要运行完整的Java EE App Server。在测试过程中,我注意到在向服务器提交空字段时,只有一个长度验证器和没有必需的属性,Glassfish正在输出验证消息,而Tomcat只是简单地跳过对这些元素的验证。



如果提交值并且验证失败,那么一切正常,只需输入值并提交页面即可。



环境细节




  • JSF Mojarra 2.1.12

  • Richfaces 4.1

  • 目标服务器Glassfis 3.1.2

  • 从Tomcat 7.0.27迁移

>

下面是包含所描述的行为的代码片段:



 < h:inputText id =phoneAreaCode
maxlength =3
size =2
value =#{bean.phoneArea}
style =margin-left :8px;>
< f:validateLength minimum =3/>
< a4j:ajax />
< / h:inputText>



用例(Tomcat):




  1. 如果提供了值,则会进行验证。如果值通过了验证,则页面被允许提交,如果失败,错误消息将被输出到页面。

  2. 如果未提供任何值,则不会进行验证,并允许页面提交




用例(Glassfish):




  1. 与上面相同


  2. 如果未提供任何值,则验证仍然发生并显然失败。

我通过< f:validator /> 标签以及内置标签,如< f:validateLength />



没有代码差异,只是运行代码的服务器。我搜索了Google,但我没有找到任何帮助。我不理解有关验证的事情吗?你看到有什么不对吗?



Stackoverflow问题听起来像是同一个问题,我只是没有看到解决方案来阻止我的环境以这种方式运行,或者当不需要该字段时如何禁用验证。



感谢任何帮助我解决这个问题的人。 解决方案

几天前我有一个非常类似的问题,我假设属性phoneArea 可能是一个整型或长整型。如果是这样,您可以查看此主题并另外在这一个

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.

解决方案

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.

这篇关于JSF 2.1.X验证在Glassfish 3.1.2与Tomcat 6&amp; 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆