如何从h:commandLink重定向URL [英] How redirect the url from h:commandLink

查看:184
本文介绍了如何从h:commandLink重定向URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还记得对吗,否则立即设置为true的参数应该更改浏览器的网址吗? 如果正确,为什么此链接无法正常工作?

Do I remember right or the parameter immediate set to true should change the url of the browser? If it is correct, why doesn't this link works properly?



    <h:form>
    <h:commandLink immediate="true" action="/url_page.xhtml" value="Label link"/>
    </h:form>

经过一番研究,我发现了一个问题,即作者在字符串中添加了字符串?faces-redirect = true" ...是否可以像我那样工作?我应该再设置一些东西吗? 谢谢您的帮助.

After some research I found a question where the author added the string "?faces-redirect=true" to the url... Is it work like I would? Should I set something else? Thank you for your help.

P.S .:我也尝试了h:link,但也许它并没有执行所有操作,因为在那之后下一页返回nullpointerException,但是URL随我的便改变了.

P.S.: I tried also h:link but, perhaps, it doesn't execute all thing because after that the next page returns a nullpointerException but the url change as I want...

解决方案完成:我将h:commandLink的操作更改为调用返回/url_page?faces-redirect = true的方法,因为我发现NULL指针异常已进入servlet过滤器... 谢谢@BalusC和@Matt!

Solution complete: I change the action of my h:commandLink to call a method that returns /url_page?faces-redirect=true because I found that nullpointer exception was into a servlet-filter... Thank you @BalusC and @Matt !

推荐答案

我还记得对吗,还是应该立即将参数设置为true? 更改浏览器的网址?

Do I remember right or the parameter immediate set to true should change the url of the browser?

此属性没有其他用途.

您可以使用h:link进行导航. h:commandLink需要一个bean方法作为action属性.动作方法的结果是导航目标.如果action方法返回null或是void方法,则将重新加载当前页面.如果返回String,JSF将使用它并导航到该结果.

You can use h:link for navigation. h:commandLink needs a bean method as action attribute. The outcome of the action method is the navigation target. If the action method returns null or is a void method, the current page will be reloaded. If it returns a String, JSF will take it and navigate to that outcome.

如果要从操作方法执行重定向,则可以在结果中添加?faces-redirect=true,例如

If you want to perform a redirection from your action method, you can add ?faces-redirect=true to your outcome, e.g.

return "login?faces-redirect=true";

这篇关于如何从h:commandLink重定向URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆