Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsf2: form: GET method

Tags:

forms

get

jsf-2

I am trying to construct equivalent of this code in JSF2

                <form action="/search.xhtml" method="get">
                    <div class="search">
                        <input type="hidden" name="mutation" value="#{facesContext.viewRoot.locale}" />
                        <input name="searchString" class="text" />
                        <input type="submit" class="searchSubmit" value="#{msg.searchIt}" />
                    </div>
                </form>

The point of this construction is to redirect user to the search.html page, which shows the search results. The page uses URL params to decode the searchString and language mutation. And because it uses get, it is also bookmarkable.

With JSF2 I tried to use the h:button with param for the mutation, but I dont have a clue, how to force jsf to encode the h:inputText searchString.

Thanks for your help.

like image 673
malejpavouk Avatar asked Sep 28 '26 16:09

malejpavouk


1 Answers

As far as I know, there is no possibility to use method="GET" in JSF. It is not what you exactly want, but may be using post-redirect-get pattern can solve your issue:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
    <f:metadata>
       <f:viewParam name="searchString" value="#{requestScopedBean.searchString}"/>
       <f:viewParam name="mutation" value="#{requestScopedBean.mutation}"/>
    </f:metadata>
    <h:body>
        <h:form>
            <h:inputText value="#{requestScopedBean.searchString}"/>
            <h:commandButton value="submit" action="/tests/search?faces-redirect=true&amp;includeViewParams=true">
                <f:param name="mutation" value="whatever"/>
            </h:commandButton>
        </h:form>
    </h:body>

</html>

More about PRG pattern in JSF2 in this article: http://www.warski.org/blog/?p=185

like image 59
Dmitry Avatar answered Sep 30 '26 12:09

Dmitry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!