primefaces:actionListener和重定向同时进行

sta*_*aru 6 java primefaces

我想点击一下

   <p:commandButton>
Run Code Online (Sandbox Code Playgroud)

,调用用于处理的Bean,同时应将页面重定向到另一个页面.

换句话说,我想结合:

<p:commandButton actionListener="#{processBean.process}" >
</p:commandButton> 
Run Code Online (Sandbox Code Playgroud)

和:

<h:link outcome="redirection"> 
</h:link>
Run Code Online (Sandbox Code Playgroud)

在faces-config.xml中配置"重定向"

我应该怎么做 ?有没有更好的方法来实现这一目标?

Mak*_*kky 4

使用action属性p:commandButton.

<p:commandButton actionListener="#{processBean.process}" >
</p:commandButton> 
Run Code Online (Sandbox Code Playgroud)

将其更改为

<p:commandButton actionListener="#{processBean.process}" action="viewIDToRedirect" >
</p:commandButton> 
Run Code Online (Sandbox Code Playgroud)

首先,actionListener将被调用,然后导航将启动。但请记住,您需要在中定义导航规则faces-config.xml

  • @Mr.Chowdary 在我的回答中,该方法返回的字符串是操作 ID,现在您可以检查那里是否有任何错误,然后返回 null (2认同)