JSF:在操作方法中返回 null 仅刷新输入文本,但不刷新组合框

发布于 2024-12-16 18:58:11 字数 218 浏览 2 评论 0原文

我想重置我的 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 技术交流群。

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

发布评论

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

评论(1

美胚控场 2024-12-23 18:58:11

从操作方法返回结果会导致构造视图的新实例(带有新的组件树)。如果您返回 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.

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