Reputation: 1221
I'm writing a simple menu using PrimeFaces, and I'm wondering if I can access a tag attribute within itself. Let me explain:
...
<p:menuitem value="#{labels['menu.home']}" url="/pages/index.jsf"
styleClass="#{view.viewId == '/pages/index.jsf' ? 'nav-selected-menuitem' : ''}"/>
...
Since this will be repeated for more pages, is there a way to do something of the sort:
<p:menuitem value="#{labels['menu.home']}" url="/pages/index.jsf"
styleClass="#{view.viewId == url ? 'nav-selected-menuitem' : ''}"/>
Where url
is the same url
attribute in this p:menuitem tag.
Is this doable?
Upvotes: 1
Views: 42
Reputation: 1108632
The component itself is available by #{component}
.
So, this should do:
<p:menuitem ... url="/pages/index.jsf"
styleClass="#{view.viewId == component.url ? 'nav-selected-menuitem' : ''}" />
Noted should be that this may fail if the component's renderer is badly implemented (i.e. it doesn't properly do pushComponentToEL()
as mandated by encodeBegin()
). This is in turn worth an issue report at component library maintainer.
Upvotes: 1