行动阶段的JSF验证 [英] JSF validation in action phase

查看:73
本文介绍了行动阶段的JSF验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个基于JSF的Web应用程序,该应用程序将输入表单数据提交到 web服务,然后显示 web服务提供的响应.

We have a JSF based web application which submits the input form data to a web service and then displays the response provided by web service.

这是网络服务,用于验证用户输入的输入数据.我不确定如何在此处使用JSF validation.根据我的理解,JSF会验证视图中的各个组件.但是每次都发出Web服务请求将是非常昂贵的操作.

It is the web service that validates the input data entered by the user. I'm not sure how we can use the JSF validation here. As per my understanding JSF validates individual components in the view. But it will be very expensive operation to make a web service request each time.

相反,当用户提交表单时,我们将跳过所有验证,并在action方法中提出Web服务请求.基于Web服务的响应,我们能否以编程方式判断特定的UI组件无效?

Instead, when the user submits the form, we skip all validations, make the web service request in the action method. Based on the response from the web service, can we programmatically tell that the particular UI component is invalid?

请问您对此有何建议?

环境:-

JSF 2.0
WebSphere Application Server 8.5

推荐答案

基于Web服务的响应,我们能否以编程方式判断特定的UI组件无效?

是的,您可以通过调用 UIInput#setValid() ,并通过false.这是完整的片段:

Yes, you can do that by calling UIInput#setValid(), passing false. Here's the complete piece:

FacesContext context = FacesContext.getCurrentInstance();
UIInput input = (UIInput) context.getViewRoot().findComponent("form:input");
input.setValid(false);
context.addMessage(input.getClientId(context), message);
context.validationFailed();

顺便说一句,不必按每个输入调用FacesContext#validationFailed().

The FacesContext#validationFailed() doesn't need to be called on a per-input basis by the way.

这篇关于行动阶段的JSF验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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