jsf2:形式:GET方法

mal*_*ouk 3 forms get jsf-2

我正在尝试在 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>
Run Code Online (Sandbox Code Playgroud)

此构造的目的是将用户重定向到 search.html 页面,该页面显示搜索结果。该页面使用 URL 参数来解码 searchString 和语言突变。而且因为它使用 get,所以它也是可添加书签的。

对于 JSF2,我尝试使用带有参数的 h:button 进行突变,但我不知道如何强制 jsf 对 h:inputText searchString 进行编码。

感谢您的帮助。

Dmi*_*try 5

据我所知,在 JSF 中不可能使用 method="GET" 。这不是您真正想要的,但使用 post-redirect-get 模式可能可以解决您的问题:

<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>
Run Code Online (Sandbox Code Playgroud)

有关 JSF2 中 PRG 模式的更多信息,请参阅本文:http://www.warski.org/blog/? p=185