使用JSF Framework验证多个字段的最佳方法是什么?

时间:2021-04-30 20:04:47

I need validate multiple fields in the JavaScript Framework, but can't figure out how.

我需要在JavaScript框架中验证多个字段,但无法弄清楚如何。

2 个解决方案

#1


What kind of validation do you need?

你需要什么样的验证?

  • Client side: you must use a Javascript validation framework. For example, this one is a good validation framework using jQuery.
  • 客户端:您必须使用Javascript验证框架。例如,这是一个使用jQuery的良好验证框架。

  • Server side: you just need to use <f:validateXXX/> components. For exmaple, <f:validateLength minimum="2" maximum="8"/> will check that the field contains a value that has a size between 2 and 8 characters. Otherwise, it will throw an Exception. Note that there a few validator by default, and you will not be able to validate an email address, or something like that. However, it is really easy to develop your own validator...
  • 服务器端:您只需要使用 组件。例如, 将检查该字段是否包含大小在2到8个字符之间的值。否则,它将抛出异常。请注意,默认情况下会有一些验证程序,您将无法验证电子邮件地址或类似的内容。但是,开发自己的验证器真的很容易......

  • Server side, using Ajax. This is almost the same thing as the previous type of validation, except that the validation is ajaxified, which means that a request will be sent to the server once the user fills a field, and then validate the field. This is usefull to check on the fly the value. The component library Richfaces offers such features.
  • 服务器端,使用Ajax。这几乎与之前的验证类型相同,只是验证是ajaxified,这意味着一旦用户填写字段,请求将被发送到服务器,然后验证该字段。这有助于即时检查值。组件库Richfaces提供了这样的功能。

#2


JSF has validation framework that can be used for simple validations. Like mandatory, length, format etc. In addition it allows you to write custom validators which are invoked for field validations once configured in myfaces file.

JSF具有可用于简单验证的验证框架。像强制,长度,格式等一样。此外,它允许您编写自定义验证器,一旦在myfaces文件中配置,就会调用这些验证器进行字段验证。

Also a bunch of fields can be grouped into "SubForms" which will let you validate several fields in a go. A seamless validation without page being submitted would require Ajax integration. (Richfaces is a good option)

此外,还可以将一组字段分组为“SubForms”,这样您就可以在一个go中验证多个字段。无需提交页面的无缝验证将需要Ajax集成。 (Richfaces是个不错的选择)

#1


What kind of validation do you need?

你需要什么样的验证?

  • Client side: you must use a Javascript validation framework. For example, this one is a good validation framework using jQuery.
  • 客户端:您必须使用Javascript验证框架。例如,这是一个使用jQuery的良好验证框架。

  • Server side: you just need to use <f:validateXXX/> components. For exmaple, <f:validateLength minimum="2" maximum="8"/> will check that the field contains a value that has a size between 2 and 8 characters. Otherwise, it will throw an Exception. Note that there a few validator by default, and you will not be able to validate an email address, or something like that. However, it is really easy to develop your own validator...
  • 服务器端:您只需要使用 组件。例如, 将检查该字段是否包含大小在2到8个字符之间的值。否则,它将抛出异常。请注意,默认情况下会有一些验证程序,您将无法验证电子邮件地址或类似的内容。但是,开发自己的验证器真的很容易......

  • Server side, using Ajax. This is almost the same thing as the previous type of validation, except that the validation is ajaxified, which means that a request will be sent to the server once the user fills a field, and then validate the field. This is usefull to check on the fly the value. The component library Richfaces offers such features.
  • 服务器端,使用Ajax。这几乎与之前的验证类型相同,只是验证是ajaxified,这意味着一旦用户填写字段,请求将被发送到服务器,然后验证该字段。这有助于即时检查值。组件库Richfaces提供了这样的功能。

#2


JSF has validation framework that can be used for simple validations. Like mandatory, length, format etc. In addition it allows you to write custom validators which are invoked for field validations once configured in myfaces file.

JSF具有可用于简单验证的验证框架。像强制,长度,格式等一样。此外,它允许您编写自定义验证器,一旦在myfaces文件中配置,就会调用这些验证器进行字段验证。

Also a bunch of fields can be grouped into "SubForms" which will let you validate several fields in a go. A seamless validation without page being submitted would require Ajax integration. (Richfaces is a good option)

此外,还可以将一组字段分组为“SubForms”,这样您就可以在一个go中验证多个字段。无需提交页面的无缝验证将需要Ajax集成。 (Richfaces是个不错的选择)