I have a p:commandLink
and would like to make it so that the controller decides its action, based on a parameter.
That's what I have:
<p:commandLink
action="#{controller.getAction(rownum)}"
title="Go"
styleClass="ui-icon ui-icon-refresh centered"
ajax="false"
disabled="#{controller.isLinkDisabled(rownum)}">
<f:param name="controllerId" value="#{otherController.getId()}" />
</p:commandLink>
rownum
is the rowIndexVar
of the p:dataTable
the button is in.
The controller method is:
public String getAction(Integer id) {
if(id == 0) {
LOG.info("Id is 0"); //LOG is a log4j logger
return "toDestinationOne";
} else {
LOG.info("Id is not 0");
return "toDestinationTwo";
}
}
It doesn't work.
If I press the button in the first row of the dataTable, in the log I see
Id is 0
So it means that the method gets called correctly, but for some reason it's ignoring the returned value, the page gets simply refreshed, I'm not getting redirected to the new page.
Both strings are in the faces-config.xml
:
<navigation-case>
<description>To destination one</description>
<from-action>toDestinationOne</from-action>
<from-outcome>toDestinationOne</from-outcome>
<to-view-id>/pages/destinationOne.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<description>To destination two</description>
<from-action>toDestinationTwo</from-action>
<from-outcome>toDestinationTwo</from-outcome>
<to-view-id>/pages/destinationTwo.xhtml</to-view-id>
</navigation-case>
If I directly put the value instead, it works properly.
I mean, this:
<p:commandLink
action="toDestinationOne"
title="Go"
styleClass="ui-icon ui-icon-refresh centered"
ajax="false"
disabled="#{controller.isLinkDisabled(rownum)}">
<f:param name="controllerId" value="#{otherController.getId()}" />
</p:commandLink>
Works properly, I get succesfully redirected to the desired page.
So, is there a way to make the commandLink
follow the action
returned by the getAction
method?