简体   繁体   中英

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. 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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