JSF:在操作方法中返回 null 仅刷新输入文本,但不刷新组合框
我想重置我的 JSF 表单。我实现了一个 Action
方法来重置支持 bean 中的所有属性。
当我返回再次转发到同一页面的 String
时,所有表单条目都会重置。输入文本框以及组合框。
但是,当我返回 null 时,仅重置输入文本框,而不重置组合框。
我不明白这种行为。两种方式都调用相同的方法,都转发到相同的页面。
I want to reset my JSF form. I've implemented an Action
method that resets all properties in the backing bean.
When I return a String
that forwards to the same page again, all form entries are reset. Input text boxes as well as comboboxes.
But when I return null
only the input text boxes are reset, not the comboboxes.
I don't understand this behavior. Both ways call the same method, both forward to the same page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从操作方法返回结果会导致构造视图的新实例(带有新的组件树)。如果您返回
null
,则会重用现有视图实例(现有组件树)。JSF 中的组件允许有状态。例如,如果验证失败,JSF 不会更新模型(backingbean),但仍然重新呈现用户输入的无效数据。这是通过将无效数据保留在组件中来实现的。
Returning an outcome from an action method causes a new instance of the view (with a new component tree) to be constructed. If you return
null
instead, the existing view instance (the existing component tree) is reused.Components in JSF are allowed to be stateful. For instance, JSF does not update the model (the backingbean) if validation fails, but still rerenders the invalid data the user entered. This is implemented by keeping the invalid data in the component.