开发者

JSF2: How to send a GET request from a button submitting input values?

开发者 https://www.devze.com 2023-04-05 16:40 出处:网络
Is this possible to pass inputs in a GET req开发者_JS百科uest from a JSF button? For example for the following elements, I want button to redirect user to something like: search-page.xhtml?input=user

Is this possible to pass inputs in a GET req开发者_JS百科uest from a JSF button?

For example for the following elements, I want button to redirect user to something like: search-page.xhtml?input=userSearchText, so that my search page is bookmarkable.

<h:inputText value="#{bean.searchText}"/>
<h:button outcome="search" />


It's not possible by alone a <h:button>. It's really a simple redirect-button, not a form submit button.

Since you do not need to set anything in the bean by POST, you can use a normal HTML GET <form> and replace the JSF components by their normal HTML representation so that you have fine grained control over the input names:

<form action="search-page.xhtml">
    <input name="input" value="#{bean.searchText}" />
    <input type="submit" />
</form>

The only disadvantage is that you can't utilize JSF implicit navigation by outcome. But that shouldn't be a major showstopper imo.

0

精彩评论

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

关注公众号