开发者

jsf2: form: GET method

开发者 https://www.devze.com 2023-03-20 04:05 出处:网络
I am trying to construct equivalent of this code in JSF2 <form action=\"/search.xhtml\" method=\"get\">

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 开发者_Python百科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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号