rion18
rion18

Reputation: 1221

Accessing tag attribute within the same tag without using binding

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

Answers (1)

BalusC
BalusC

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.

See also:

Upvotes: 1

Related Questions