如何使用< f:ajax>以简单的< form>而不是< h:form&gt ;? [英] How to use <f:ajax> in a plain <form> instead of <h:form>?

查看:52
本文介绍了如何使用< f:ajax>以简单的< form>而不是< h:form&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用标准HTML < form> 标记的搜索表单,并发送了GET请求,例如 search.jsf?country = x& city = y .它们在视图范围的bean中设置为视图参数.

I have a search form which uses standard HTML <form> tag and sends a GET request like so search.jsf?country=x&city=y. They are set as view parameters in a view scoped bean.

搜索表单包含两个层叠的下拉菜单,一个用于国家,一个用于城市.如何在不将< form> 更改为< h:form> 的情况下通过< f:ajax> 更新城市下拉列表破坏了GET功能?是否必须通过 XMLHttpRequest 使用普通香草" ajax?我如何在JSF支持bean上使用它?

The search form contains two cascading dropdowns, one for countries and one for cities. How can I update the cities dropdown by <f:ajax> without changing <form> to <h:form> and thus breaking the GET functionality? Do I have to use "plain vanilla" ajax by XMLHttpRequest? How could I use it on a JSF backing bean?

推荐答案

我将继续使用< h:form> 并向JavaScript寻求帮助,以便在任何时候将其转换为GET表单它是通过提交"按钮提交的.

I'd just keep using <h:form> and ask some assistance to JavaScript to turn it into a GET form whenever it's been submitted by the submit button.

类似的东西:

<h:form prependId="false" onsubmit="doGet(this)">
    <h:selectOneMenu id="country" value="#{bean.country}">
        <f:selectItems value="#{bean.countries}" />
        <f:ajax listener="#{bean.loadCities}" render="city" />
    </h:selectOneMenu>
    <h:selectOneMenu id="city">
        <f:selectItems value="#{bean.cities}" />
    </h:selectOneMenu>
    <input type="submit" value="Search" />
</h:form>

使用此JS将其转换为GET形式,并删除两个< h:form> 特定的隐藏字段:

with this JS to turn it into a GET form and removing the two <h:form> specific hidden fields:

function doGet(form) {
    form.method = "get";
    form.removeChild(document.getElementsByName(form.name)[1]);
    form.removeChild(document.getElementById("javax.faces.ViewState"));
}

这篇关于如何使用&lt; f:ajax&gt;以简单的&lt; form&gt;而不是&lt; h:form&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆