Spring Menu Configuration

天涯浪子 提交于 2020-01-06 09:52:05

问题


I am working with the spring MVC 4 and configuring the menu in my home page which is to be shown based on role which i have define. So in my menu-config.xml i am defining as

<Menu name="Company" title="menu.companyTitle" page="/xxx/yyy/zzzz">
   <Item name="NewCompanyRequest" roles="ROLE_ADMIN,ROLE_USER" title="menu.NewCompanyRequest" page="/admin/companyRequestList" />
   <Item name="editCompanies" roles="ROLE_ADMIN" title="menu.editCompanies" page="/xx/yyy/ccc" />
</menu>
<Menu name="Exchaged" title="menu.admin.aboutCompany" page="/exchaged" roles="ROLE_ADMIN,ROLE_USER"/>  

Means the above item name editCompanies should be visible to ADMIN user only and it is working fine but in UI it disturbed the next menu Exchaged and bring in one.

I have tried to number of steps but din't work and not found solution.


回答1:


First of all, You are using wrong closing tag for Your <Menu> tag. I have corrected it and You can see it below code.

Next, You cannot add roles attribute in <Item> tag. You have to give this attribute in <Menu> tag instead. So, Your menu should be like below:

<Menu name="Company" title="menu.companyTitle" page="#" roles="ROLE_ADMIN,ROLE_USER">
    <Item name="NewCompanyRequest"  title="menu.NewCompanyRequest" page="/admin/companyRequestList" />
    <Item name="editCompanies" title="menu.editCompanies" page="/xx/yyy/ccc" />
</Menu> ...

or like below:

<Menu name="Company" title="menu.companyTitle" page="/xxx/yyy/zzzz" roles="ROLE_ADMIN">
    <Item name="NewCompanyRequest"  title="menu.NewCompanyRequest" page="/admin/companyRequestList" />
    <Item name="editCompanies" title="menu.editCompanies" page="/xx/yyy/ccc" />
</Menu> ...

or You can make dropdown menus separate menu and give separate role permission like below:

<Menu name="NewCompanyRequest" roles="ROLE_ADMIN,ROLE_USER" title="menu.NewCompanyRequest" page="/admin/companyRequestList" />
<Menu name="editCompanies" roles="ROLE_ADMIN" title="menu.editCompanies" page="/xx/yyy/ccc" />


来源:https://stackoverflow.com/questions/28602419/spring-menu-configuration

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