expanded attribute on subMenu not taken into account

纵饮孤独 提交于 2019-12-10 16:41:48

问题


I have a panelMenu with some submenus inside whose expanded attribute is controlled on a backing bean. The issue is, the expanded status of the different submenus seems to be cached by the browser, depending on the previous status of each submenu the previous time the user was on that url, ignoring the boolean status set to expanded. The behaviour is the same with p:panelMenu and with p:menu.

You can reproduce the issue on a PF project, adding the following code to a jsf page. No backing bean required. The first time the page is loaded, the submenu in the middle will appear as collapsed. After playing a bit with the menu if the page is reloaded, the expanded attribute is not taken into account anymore, and the way the page is display responds to the last configuration the user had on the browser.

<h:form>
    <p:panelMenu toggleable="true">
        <p:submenu label="No expandido" expanded="false">
            <p:menuitem value="External" url="http://www.primefaces.org"/>
        </p:submenu>
        <p:submenu label="Expandido" expanded="true">
            <p:menuitem value="External" url="http://www.primefaces.org"/>
        </p:submenu>
        <p:submenu label="No expandido" expanded="false">
            <p:menuitem value="External" url="http://www.primefaces.org"/>
        </p:submenu>
    </p:panelMenu>
</h:form>

Attending to the manual, this behaviour is not the expected one:

           expanded - false - Boolean - Defines the state of submenu.

... and according to a post by Cagatay in the PF forum, panelMenu is already ready to use the expanded attribute.

Question is, is there a way to set the status expanded/not expanded of subMenu elements inside of a panelMenu or a menu?

Thanks for any comment/suggestion/workaround.

Primefaces 5.2 | Tomcat 7.0.X | Chrome + IE11


回答1:


Have you tried setting the stateful attribute of the panelMenu:

<p:panelMenu stateful="false">

This disables the menu from being cache to a cookie.




回答2:


I had similar issue, the cause was having multiple f:viewAction inside f:metadata. merging them into one, solved the issue.



来源:https://stackoverflow.com/questions/30484925/expanded-attribute-on-submenu-not-taken-into-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!