使用 primefaces保留所选项目单击向导组件的“下一步”/“后退”时

发布于 2024-12-26 01:49:38 字数 544 浏览 1 评论 0原文

wizard 组件中使用 primefaces 时,按下 NEXT 和 BACK 按钮时无法保留所选项目。例如,在

<h:outputText value="Roles" />
<p:selectManyMenu id="role" value="#{backingBean.rolesList}"
    style="height:75px">
    <f:selectItems value="#{backingBean.secRole}" var="roles"
        itemLabel="#  {roles.roleName}" itemValue="#{roles.roleId}">
    </f:selectItems>
</p:selectManyMenu>

itemLabel 中,当我按 NEXT/BACK 按钮时,所选内容将被刷新。如何保留所选值?

While using primefaces <p:selectManyMenu> in wizard component , the item selected could not be retained while pressing the NEXT and BACK button. For example in

<h:outputText value="Roles" />
<p:selectManyMenu id="role" value="#{backingBean.rolesList}"
    style="height:75px">
    <f:selectItems value="#{backingBean.secRole}" var="roles"
        itemLabel="#  {roles.roleName}" itemValue="#{roles.roleId}">
    </f:selectItems>
</p:selectManyMenu>

itemLabel selected will be flushed out when I press NEXT/BACK button.How can I retain the selected value there?

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

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

发布评论

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

评论(1

夏见 2025-01-02 01:49:38

正如我之前的评论中提到的,使用 JSF ManagedBeans 的 Spring 3 依赖注入时,@ViewScoped bean 不起作用。无论您使用注释还是 faces-config.xml 来声明托管 bean,ViewScoped 仍然不会维护对话样式范围。

我为解决此问题所做的工作是使用 @SessionScoped 代替,但这可能是一个问题,因为下次用户导航到此页面时,先前的状态仍然存在,而您可能实际上想要该状态重置。通过在离开页面之前将 actionListener 导航方法上的 bean 属性设置为默认值,可以部分解决此问题。但是,如果用户要在地址栏中手动键入页面,然后返回,这将无济于事。或者,他们可能将您的 Web 应用程序的一个或多个 URL 存储在他们的收藏夹或书签中。

解决此问题的更好方法是让其他 RequestScoped bean 或其他页面特定 bean 在创建时找到特定 SessionScoped bean 并调用其公共方法,将 bean 属性重置为其默认值。或者,您可以简单地从会话中完全删除 SessionScoped bean,下次请求时将重新创建它。

As mentioned in my previous comment, @ViewScoped beans do not work when using Spring 3 dependency injection of JSF ManagedBeans. It doesn't matter if you use annotations or faces-config.xml to declare your managed beans, ViewScoped will still not maintain conversation style scope.

What I do to work around this issue is to use @SessionScoped instead, however this can be a problem because the next time the user navigates to this page the previous state still exists where you may actually want the state to reset. This can be partially solved by setting your bean properties to default values on an actionListener navigation method before navigating away from the page. This won't help however if the user were to manually type a page in the address bar, and then return. Or perhaps they have one or more URL's of your web application stored in their Favorites or Bookmarks.

A better way to fix this would be to have your other RequestScoped beans or other page specific beans on creation find the specific SessionScoped bean and call a public method on it that resets your beans properties to their default values. Or you can simply remove the SessionScoped bean from the session altogether and the next time it is requested it will be recreated.

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