ajax - 如何使用 ajax 事件和渲染消息通过 @FacesValidator 执行单个输入验证?
问题描述
用法:JSF 2.3.2 Mojarra
在将 ajax 添加到我的 jsf 时,我遇到了这样的情况:
无法刷新:h:message id="phoneNumber-msg"在填写表单期间
<h:messages id="validation-messages" styleClass="validation-messages"/>
<h:form>
<h:outputLabel for="phoneNumber">Phone number</h:outputLabel>
<h:inputText id="phoneNumber" value="#{bean.phoneNumber}">
<f:validator validatorId="validators.PhoneNumber"/>
<f:ajax event="blur" execute="@this" render="phoneNumber-msg"/>
</h:inputText>
<h:message id="phoneNumber-msg" for="phoneNumber"/>
[...]
<h:commandButton value="Submit" action="#{userDetails.submit}"/>
</h:form>
和validators.PhoneNumber是一个@FacesValidator:
@FacesValidator("validators.PhoneNumber")
public class PhoneNumberValidator implements javax.faces.validator.Validator {
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { ... }
}
此外
当通过结束表单的“提交”按钮刷新时,验证工作正常(来自validators.PhoneNumber的消息同时出现在:id="validation-messages"和id="phoneNumber-msg" ):
<h:commandButton value="Submit" action="#{userDetails.submit}"/>
</h:form>
如果您考虑不同的验证方式 - > 在 EmailAddress 输入中,我使用了我自己的类注释(EmailAddressValidator 实现 ConstraintValidator),它通过表单中使用的 bean 上的 @ValidEmailAddress 进行验证 - 它正确呈现电子邮件验证消息,但在这里我想以不同的方式验证电话号码。
是否可以呈现id="phoneNumber-msg"(这意味着在填写表单期间进行验证器。电话号码?
解决方案
推荐阅读
- integral - 绘制由参数积分定义的函数
- python - %H:%M:%S.%f 格式在我的熊猫数据框中不一致
- jspdf - jsPDF图像在错误的页面上一直以错误的顺序显示
- java - 每当我在色轮外滑动时,我的应用程序就会崩溃
- python - PyAudio 如何将频率范围分组在一起
- php - 客户使用礼品卡付款时绕过“计费”部分 - woocommerce
- objective-c - 在 Objective-C 中公开 Swift 枚举数组
- sql - 我想在每个相同的日期汇总数据
- javascript - 在云中存储变量的最佳方法是什么?
- sql - 如何从 db2 中的 xml 字符串中读取值