sách gpt4 ai đã đi

validation - 当验证错误期间添加 Faces 消息时,JSF 会跳过调用应用程序阶段吗?

In lại 作者:行者123 更新时间:2023-12-02 14:11:27 26 4
mua khóa gpt4 Nike

我需要你的帮助才能更好地理解这一点。这是我的情况。我为表单中的每个输入控件都有一个自定义验证器。因此,当出现任何验证错误时,我在验证方法中添加相应的 FacesMessage。我的理解是,当出现任何验证错误时 - 或者在自定义验证器的验证方法中添加任何 FacesMessage 时,它将跳过 INVOKE APPLICATION 阶段并直接调用 RENDER RESPONSE 阶段 - 显示添加的 FacesMessage流程验证阶段 - 这是正确的吗?

我面临的问题是 - 我在过程验证阶段添加了 FacesMessage - 由于验证错误 - 并且我为用户在调用应用程序阶段所采取的操作添加了一条确认消息 - 现在两者显示在渲染响应阶段的页面中? - 如果我对上述问题的理解是正确的 - 在确认当前 FacesContext 中没有 FacesMessages 后,有条件地添加确认 FacesMessage 是最佳实践吗?

这是添加消息的方式:

FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR,Constants.invalidMessageDetail,null);
FacesContext.getCurrentInstance().addMessage(null, facesMessage);
throw new ValidatorException(facesMessage);

显示方式如下:


感谢您的帮助。

1 Câu trả lời

My understanding was that when there is any validation error - or when there are any FacesMessages added in the validate method of the Custom Validator, it would skip the INVOKE APPLICATION phase and would directly call the RENDER RESPONSE PHASE - showing the FacesMessage that was added in the PROCESS VALIDATION Phase - Is this correct?

部分正确。仅当抛出时,它才会跳过更新模型值并调用应用程序阶段,而不是简单地将FacesMessageThêm vàoFacesContext.

If my understanding is correct in the above question - is it the best practice to conditionally add a confirmation FacesMessage after confirming that there are no FacesMessages in the currect FacesContext ?

您需要抛出ValidatorException, như được hiển thị bên dưới:

public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
if (value does not meet conditions) {
throw new ValidatorException(new FacesMessage("value does not meet conditions"));
}
}

然后它将跳过更新模型值并根据需要调用应用程序阶段。请注意,您不需要手动将面孔消息添加到上下文中。当 JSF 捕获 ValidatorException 时,它会自行完成这一切。

关于validation - 当验证错误期间添加 Faces 消息时,JSF 会跳过调用应用程序阶段吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2949113/

26 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com