Sebastian Wramba
Sebastian Wramba

Reputation: 10127

Avoid separate function for commandLink action

I would like to use a property of a form element instead of using an additional function to just return a certain value.

Current situation

XHTML file:

<h:commandLink action="#{menuBean.navigationAction(menuItem)}" ... >

Managed Bean behind it:

public function navigationAction(MenuItem entry) {
    return entry.getForward();
}

Desired situation

I would like to skip the method call and directly use the property of menuItem to set the destination. Like this:

<h:commandLink action="#{menuItem.forward}" />

This does unfortunately not work, as the method cannot be found. Is it even possible to do so?

Upvotes: 1

Views: 266

Answers (1)

Matt Handy
Matt Handy

Reputation: 30025

You could try this:

<h:link outcome="#{menuItem.forward}" .../>

The outcome parameter takes a value expression that must resolve to a string. The action attribute of h:commandLink needs a method expression.

Upvotes: 1

Related Questions