java 单击导航栏中的项目时如何重定向到另一个页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5729464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to redirect to another page when i click on an item, in my navigation bar
提问by sfrj
I use a navigation tool called dock, from primefaces. I need to redirect to another page when i click on one of the items. The problem is that i need to find an alternative to the url attribute, this is because if i use it, the page gets redirected and the action attribute don't makes a call to the method is supposed to call.
我使用了一个来自primefaces 的名为dock的导航工具。当我单击其中一个项目时,我需要重定向到另一个页面。问题是我需要找到 url 属性的替代方法,这是因为如果我使用它,页面会被重定向并且 action 属性不会调用应该调用的方法。
This is how my nav bar looks like:
这是我的导航栏的样子:
<h:form>
<p:dock position="top">
<!--Some other menu items ...-->
<p:menuitem value="Logout" icon="unsecuredimages/logout.png" action="#{securityController.logOut}" rendered ="#{!securityController.checkLogged}"/>
</p:dock>
</h:form>
This is the backing bean that is called to do the logout. It works good the only problem is that i don't get redirected.
这是被调用以进行注销的支持 bean。它运行良好,唯一的问题是我没有被重定向。
@ManagedBean
@RequestScoped
public class SecurityController {
@EJB
private IAuthentificationEJB authentificationEJB;
public String logOut() {
authentificationEJB.releaseUserState();
return "main.xhtml";
}
...
As you see i tried to return an String form the backing bean method, but doesn't work.
如您所见,我尝试从支持 bean 方法返回一个字符串,但不起作用。
Could you help me find the way to redirect when i click on the p:menuItem?
当我点击 p:menuItem 时,你能帮我找到重定向的方法吗?
Do you know maybe some javascript trick or something similar i can use to get redirected when i click?
你知道当我点击时我可以使用一些 javascript 技巧或类似的东西来重定向吗?
回答by Jigar Joshi
Use
利用
return "main.xhtml?faces-redirect=true";