Skip to content

AbstractMenu: "renderEmptyContainer" option to prevent empty menus from being rendered #12743

@gako

Description

@gako

Description

I often encounter cases were I use some kind of menu/container component (MenuButton, Menubar, Toolbar, ...) with a list of menu items that are either rendered or not depending on the current rights of the user. In cases where the current user has none of the required rights the menuButton is still rendered and can be clicked but an empty popup is shown.

E.g "Action" MenuButton with Menu Items for "Edit", "Delete", "Print" each having its own rendered definition
<p:menuButton value="actions"> <p:menuitem value="Edit" rendered="#{checkRequirementsRights('edit')}"> <p:menuitem value="Delete" rendered="#{checkRequirementsRights('delete')}"> <p:menuitem value="Print" rendered="#{checkRequirementsRights('print')}"> </p:menuButton>

I could also add a rendered to the menuButton and combine any checks with OR but depending on the number of items this soon becomes anoying. For my toolbar this is not possible because here I define the toolbar itself in a pageTemplate and each subPage defines it's unique actions for it.

Adding a "renderEmptyContainer" (default true for backward compatibility) with a check wether any children are rendered and if not not rendering the whole component could solve this issue.

Is this something that could be added as a feature or can anyone come up with a different solution?
If yes I could provide a PR for some components where I already fixed it via an extension.

Describe the solution you would like

Components that act as some kind of container for other items (Toolbar, MenuButton, Menubar, ...) should have an option to not being rendered at all if no real children ( e.g ignore separaors) are present/rendered.

An alternative solution could be to render the component as usual but add some kind of empty marker via a css style class to the container ("ui-widget-empty" or something like that). If somebody want's to hide these components a simple .ui-widget-empty {display:none} rule would suffice. For this solution no additional attribute would be necessary since always adding the marker class should do no harm if no css rule is defined.

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions