JSF UIComponents 的更新值

发布于 2024-08-20 14:23:52 字数 448 浏览 2 评论 0 原文

我有一个带有 3 个选项的单选选项和一个 inputTextArea 的页面。当我按下页面上的提交按钮时,我需要进行一些验证......为了做到这一点,我在收音机上放置了一个验证器。问题是,当执行验证器时,我需要 inputTextArea 和 radio 的值,但它们带有旧值,而不是提交页面之前在页面上定义的值。

示例String.valueOf(textArea.getValue()).equals(""))首次提交代码时String.valueOf(textAreaOcorrencia.getValue ())null,但由于 textArea 为空,因此它应该是一个空字符串。当第二次提交时,它具有第一次提交时应有的值。我知道这与 JSF 生命周期有关,但我不知道如何更新这些值?

I have a page with a radio selection with 3 options and a inputTextArea. When I press the submit button on my page, then I need to do some validations... In order to do so, I put a validator on the radio. The problem is that when the validator is executed, I need the values of the inputTextArea and of the radio, but they come with old values, not the ones that were defined on the page before the page was submitted.

Example: String.valueOf(textArea.getValue()).equals("")) when it is first submitted the code String.valueOf(textAreaOcorrencia.getValue()) is null, but since the textArea was empty it was supposed to be an empty string. When it is submitted for the second time, it has the value of what it was supposed to have in the 1st submission. I know that this has something to do with the JSF life cycle, but I don't know how to update these values?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入画浅相思 2024-08-27 14:23:52

在应用请求值阶段,提交的值将被设置并以 subscribedValue 形式提供。在验证阶段,提交的值将被验证和转换并设置为value。当组件出现在组件树中时,组件将按照从上到下的顺序进行验证。

因此,如果相关组件实际上出现在组件树中当前组件之后,您需要通过 UIInput#getSubscribedValue() 而不是 UIInput#getValue ()

要了解有关 JSF 生命周期的更多信息,您可以找到这篇自我练习文章有用。

During the apply request values phase, the submitted values will be set and available as submittedValue. During the validations phase, the submitted values will be validated and converted and set as value. The components are validated in the top-bottom order as the components appear in the component tree.

Thus, if the component in question actually appears after the current component in the component tree, you'll need to get its value by UIInput#getSubmittedValue() instead of UIInput#getValue().

To learn more about the JSF lifecycle, you may find this self-practice article useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文