使用 primefaces保留所选项目单击向导组件的“下一步”/“后退”时
在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我之前的评论中提到的,使用 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 anactionListener
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.