我有一个带有 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?
发布评论
评论(1)
在应用请求值阶段,提交的值将被设置并以
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 asvalue
. 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 ofUIInput#getValue()
.To learn more about the JSF lifecycle, you may find this self-practice article useful.