使用GET提交JSF表单 [英] Submit a JSF form using GET
问题描述
JSF页面内容:
pre> < F:元数据>
< f:viewParam name =item1value =#{bean.item1}/>
< f:viewParam name =item2value =#{bean.item2}/>
< / f:元数据>
...
< h:表格>
< h:inputText value =#{bean.item1}/>
< h:inputText value =#{bean.item2}/>
< h:按钮值=提交>
< f:param name =item1value =#{bean.item1}/>
< f:param name =item2value =#{bean.item2}/>
< / h:按钮>
< / h:表格>
如果我请求页面:form.jsf?item1 = foo& item2 = bar,它将填充文本字段,但表单提交本身似乎并没有工作。
替换< ; h:button>
by
< h:commandButton value =Submitaction = ?形成面临重定向=真放大器;放大器; includeViewParams =真/>
它有效地激发了一个PRG(Post-Redirect-Get),它将包含< f:viewParam>
查询字符串中的参数。注意应该是目标页面必须完全相同< f:viewParam>
。
< form>
而不是< h:form>
,给输入元素一个 id
匹配参数名称并使用普通的< input type =submit>
。您当然也可以在这里使用普通的HTML < input type =text>
。 <形式>
< h:inputText id =item1value =#{bean.item1}/>
< h:inputText id =item2value =#{bean.item2}/>
< input type =submitvalue =Submit/>
< / form>
您应该仍然保留< f:viewParam>
在双方。您只需要意识到无法在此表单中完成转换/验证,则必须通过目标页面上的< f:viewParam>
执行
参见:
How do I submit a form to the same page and use GET parameters?
JSF page contents:
<f:metadata>
<f:viewParam name="item1" value="#{bean.item1}"/>
<f:viewParam name="item2" value="#{bean.item2}"/>
</f:metadata>
...
<h:form>
<h:inputText value="#{bean.item1}"/>
<h:inputText value="#{bean.item2}"/>
<h:button value="Submit" >
<f:param name="item1" value="#{bean.item1}"/>
<f:param name="item2" value="#{bean.item2}"/>
</h:button>
</h:form>
If I request the page: form.jsf?item1=foo&item2=bar, it will populate the text fields, but the form submission to itself doesn't seem to work.
Replace <h:button>
by
<h:commandButton value="Submit" action="form?faces-redirect=true&includeViewParams=true"/>
It effectively fires a PRG (Post-Redirect-Get) which will include the <f:viewParam>
params in the query string. Noted should be that the target page must have exactly same <f:viewParam>
.
Another solution is to use a plain HTML <form>
instead of <h:form>
, give the input elements an id
matching the parameter name and use a plain <input type="submit">
. You can of course also use plain HTML <input type="text">
here.
<form>
<h:inputText id="item1" value="#{bean.item1}"/>
<h:inputText id="item2" value="#{bean.item2}"/>
<input type="submit" value="Submit" />
</form>
You should still keep the <f:viewParam>
in both sides. You only need to realize that conversion/validation couldn't be done in this form, they have to be performed via the <f:viewParam>
on the target page.
See also:
这篇关于使用GET提交JSF表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!