2014-08-28 66 views
0

我有一个p:commandLink并希望使控制器根据参数决定其动作。p:commandLink - 从控制器获取动作

这就是我:

<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> 

rownump:dataTable按钮在

控制器方法的rowIndexVar

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"; 
    } 
} 

它不工作。

如果我按下按钮数据表的第一行中,在日志中我看到

Id is 0 

因此,这意味着,该方法被正确调用,但由于某种原因它忽略了返回值时,页面被刷新,我没有被重定向到新页面。

两个字符串都是在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> 

如果我直接把值来代替,它工作正常。

我的意思是,这样的:

<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> 

正常工作,我得到成功地重定向到所需的页面。

那么,有没有办法使commandLink跟在getAction方法返回的action

回答

2

的从动作必须是一样的commandLink的action属性,你的情况

#{controller.getAction(rownum)} 
+0

'#{controller.getAction(ROWNUM)}'是指可以返回两个不同的方法行动,这不是行动字符串... – BackSlash 2014-08-28 14:12:16

+0

我的意思是: dunni 2014-08-28 14:13:48

+0

好吧,让我试试吧! – BackSlash 2014-08-28 14:15:17