Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF 2.0 navigating on commandLink and commandButton doesn't work

Tags:

jsf

jsf-2

I'm using JSF 2.0 and I have a problem with navigation after both commandLink and commandButton. I use following code:

<h:commandLink action="login?faces-redirect=true" 
    value="#{showElementBean.showElement()}"> Login </h:commandLink>  

<h:commandButton action="login?faces-redirect=true" value="Move to login.xhtml" />

These tags are inside a form, login is just an example. Result of clicking on rendered controls is always POST with refresh of a current page. What do I wrong?

Edit: According to comments of BalusC I' adding real code fragment:

<h:commandLink actionListener="#{showElementBean.showElement(element)}" 
    value="View" > </h:commandLink>

I have a page with a list of elements and I want to add links that leads to element view page. Thus I need to pass this element to a show page. I'm JSF primer, e.g. in Rails I'd use GET and URL params, but I don't know how to do it 'in JSF-way'.

like image 481
mrzasa Avatar asked Nov 22 '11 11:11

mrzasa


1 Answers

There are a lot of possible causes for this behaviour. They are all cited in the following answer, along with solutions: commandButton/commandLink/ajax action/listener method not invoked or input value not updated.

However, in your particular case, you seem rather to be interested in plain GET requests instead of POST requests, as all you want is simple page-to-page navigation. In that case, you need a <h:link> or <h:button> instead:

<h:link outcome="login" value="Login" />

<h:button outcome="login" value="Move to login.xhtml" />

(I have no idea what you're trying to do with both #{showElementBean.showElement()} and Login as command link value, so I omitted the former)

See also:

  • When should I use h:outputLink instead of h:commandLink?
like image 65
BalusC Avatar answered Sep 19 '22 11:09

BalusC