How redirect the url from h:commandLink

jsf-2

Solution

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

No this attribute has a different purpose.

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.

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

Problem

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> ``` 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.: 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... 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 !

Original source