0

Is there a possibility to use both outcome and action in the same command link?

I tried

    <h:commandLink  outcome="page?faces-redirect=true" 
value="Got to Page" 
action="#{Bean.setValue("...")}" />

but it ignores the outcome.

I have a table with data like this: ID Name Other Things Link to Next Page

So I want to give the ID to the next page to show data which belongs to the selected ID from before... How could I realize this?

Liae Neya
  • 31
  • 6
  • An `` does not have the `outcome` attribute. Where did you get that it has? – Tiny Jun 21 '15 at 09:38
  • It does no say 'error' - so I tried to use it as in OutcomeLink... – Liae Neya Jun 21 '15 at 09:41
  • 1
    Use `` instead, pass that identifier (using ``), receive the parameter on the target page (using ``) and fetch the data based on the identifier in the corresponding managed bean. – Tiny Jun 21 '15 at 09:58
  • Why not pass the page in the action as well and do the redirect in the method you call? Or combine it with an actionlistener – Kukeltje Jun 21 '15 at 11:14

1 Answers1

1

You could use <f:setPropertyActionListener>.

<h:commandLink value="Edit" action="edit?faces-redirect=true">
    <f:setPropertyActionListener target="#{bean.id}" value="#{id}" />
</h:commandLink>

Or you could abuse actionListener.

<h:commandLink value="Edit" action="edit?faces-redirect=true" 
    actionListener="#{bean.setId(id)}" />

Both ways, however, would require a session scoped bean to remember the chosen id, which is plain awkward. When you open such link multiple times in different browser tabs and then interact on each them afterwards, the site's behavior would be really unintuitive and confusing.

The canonical way is to just pass it as a GET parameter.

<h:link value="Edit" outcome="edit">
    <f:param name="id" value="#{id}" />
</h:link>

The target page can get hold of it via <f:viewParam> and if necessary invoke business action on it via <f:viewAction>.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555