JSF 2.0 running on Link and commandButton not working

I am using JSF 2.0 and I have a navigation problem after commandLink and commandButton. I am using the 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 the form, login is just an example. The result of clicking on the rendered controls is always a POST with an update of the current page. What am I wrong?

Edit: According to the comments of BalusC, I am adding a real piece of code:

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

I have a page with a list of items, and I want to add links to the page for viewing items. Thus, I need to pass this element to the display page. I am a JSF primer, for example. in Rails, I would use the GET and URL parameters, but I don’t know how to do this in the JSF-way.

+5
4

. , : commandButton/commandLink/ajax action/listener .

, GET POST, , , . <h:link> <h:button>:

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

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

( , #{showElementBean.showElement()}, Login , )

. :

+8

: JSF HTML-

: CommandButton

commandButton HTML, bean ActionListener . (I18N).

<h:commandButton id="button1" value="#{bundle.checkoutLabel}" action="#{shoppingCartBean.checkout}" />

HTML

<input id="form:button1" name="form:button1" type="submit" value="Check Out" onclick="someEvent();" /> 


: commandLink

commandLink HTML, bean ActionListener . (I18N).

<h:commandLink id="link1" value="#{bundle.checkoutLabel}" action="#{shoppingCartBean.checkout}" /> 

HTML

<a href="#" onclick="someEvent();" id="form:link1">Check Out</a>
0

, bean , :   <h:form name="searchForm" enctype="multipart/form-data" method="post" action="/search">

0
source

I also ran into this problem and added    <h:form><h:commandLink></h:commandLink> </h:form> solved my problem.

-3
source

All Articles