简体   繁体   English

保留带有主字体的所选项目 <p:selectManyMenu> 在单击向导组件的NEXT / BACK时

[英]Retain selected item with primefaces <p:selectManyMenu> while clicking NEXT/BACK of wizard component

While using primefaces <p:selectManyMenu> in wizard component , the item selected could not be retained while pressing the NEXT and BACK button. wizard组件中使用素数<p:selectManyMenu>时,按NEXT和BACK按钮无法保留所选的项目。 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? 当我按下NEXT / BACK按钮时,被选中的itemLabel将被清空。如何在其中保留所选值?

As mentioned in my previous comment, @ViewScoped beans do not work when using Spring 3 dependency injection of JSF ManagedBeans. 如我先前的评论中所述,在使用JSF ManagedBeans的Spring 3依赖项注入时, @ViewScoped bean不起作用。 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. 使用注解或faces-config.xml声明托管bean无关紧要,ViewScoped仍然不会保持对话样式范围。

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. 要解决此问题,我要做的是改用@SessionScoped ,但这可能是个问题,因为下一次用户导航到此页面时,先前的状态仍然存在,您实际上可能希望重置状态。 This can be partially solved by setting your bean properties to default values on an actionListener navigation method before navigating away from the page. 在离开页面之前,可以通过在actionListener导航方法actionListener bean属性设置为默认值来部分解决此问题。 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. 或者,他们在其“收藏夹”或“书签”中存储了您的Web应用程序的一个或多个URL。

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. 解决此问题的更好方法是让您的其他RequestScoped Bean或其他页面特定的Bean在创建时找到特定的SessionScoped Bean,并在其上调用一个公共方法,将您的bean属性重置为其默认值。 Or you can simply remove the SessionScoped bean from the session altogether and the next time it is requested it will be recreated. 或者,您可以简单地从会话中完全删除SessionScoped bean,然后在下次请求时将其重新创建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM