Lukem
Lukem

Reputation: 123

JSF 2.0 commandLink: how to pass a the page number as a parameter in the browser?

I want to pass the number each of clicks page of search results from tables in the browser with JSF commandLink Tag. But it does not work. I always get the following URL: http://localhost:myport/kundenVerwaltungWebClient/searchPerson.jsf

The URL in the browser should look something like this: http://localhost:myport/kundenVerwaltungWebClient/searchPerson.jsf?pageNum=6

Here is the view (searchPerson.xhtml):

... <!-- The paging links -->
                                    <t:dataList value="#{controller.pages}" var="page">
                                        <h:commandLink value="#{page}" actionListener="#{controller.page}"
                                            rendered="#{page != controller.currentPage}" >
                                            <f:param name="pageNum" value="#{page}" />
                                        </h:commandLink>
                                        <b><h:outputText value="#{page}" escape="false"
                                            rendered="#{page == controller.currentPage}" /></b>
                                    </t:dataList> ...

Here is the managed bean:

@ManagedBean @SessionScoped public class Controller { private String pageNum; ... //Getter and Setter }

Can someone please tell me what I do wrong here?

I thank you in advance.

Upvotes: 1

Views: 992

Answers (1)

BalusC
BalusC

Reputation: 1108662

The <h:commandLink> sends a POST request, but you apparently want to send a GET request. You need to use <h:link> instead of <h:commandLink> if you want to send a GET request.

<h:link value="#{page}" rendered="#{page != controller.currentPage}" >
    <f:param name="pageNum" value="#{page}" />
</h:link>

(this doesn't require a <h:form> by the way, so you can safely remove it if you don't have any other command links/buttons in the view)

To replace the actionListener job, put this in the top of your view:

<f:metadata>
    <f:viewParam name="pageNum" value="#{controller.currentPage}" />
    <f:event type="preRenderView" listener="#{controller.page}" />
</f:metadata>

See also:

Upvotes: 1

Related Questions