F:阿贾克斯由onchange事件 [英] f:ajax by onchange event

查看:162
本文介绍了F:阿贾克斯由onchange事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特殊的问题:我需要一个值,通过客户端onchange事件发送到服务器,而无需submiting整个表单。有一些功能来做到这一点?

I have a special problem: I need to send a value to server by client onchange event without submiting the whole form. Is there some feature to do it?

我可以通过Javascript处理组件:

I can handle the component by Javascript:

<h:inputText onchange= ...js... >

和我可以通过AJAX发送值:

And I can send a value by ajax:

<f:ajax execute="name"/>

如何把它一起?

How to put it together?

这是解决了,但我还有一个问题:

It is solved, but I have another question:

什么是更快地处理 - ?事件或JavaScript处理Ajax的处理

What is processed sooner - Ajax handling of the event or JavaScript handling?

推荐答案

简单,AJAX是专为局部的提交/更新,这种情况发生在页面上。你只需要到指定的事件属性=htt​​p://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/ F / ajax.html相对=nofollow> &LT; F:AJAX&GT; 标记,并让它成为变更,你的愿望。由于每部分的形式提交,指定部件的ID来进行更新标签中的执行属性在服务器上。至于默认值执行&LT; F:AJAX&GT; 完全 @this (触发该事件的组件),你完全可以忽略它。像这样:

Easy, AJAX was designed for partial submits / updates that happen on the page. You just need to specify event attribute of <f:ajax> tag and let it be change, as you desire. As per partial form submit, specify ids of components to be updated on the server in tag's execute attribute. But as default value for execute of <f:ajax> is exactly @this (the component that fires the event), you can omit it altogether. Like so:

<h:inputText id="text" value="#{bean.text}">
    <f:ajax event="change"/>
</h:inputText>

这样的话,以后的JavaScript变化的事件发生,你的bean模型将在幕后通过AJAX更新。

This way, after JavaScript change event happens, your bean model will be updated behind the scenes via AJAX.

由于这些事件发生,你需要明白,这是触发发送AJAX请求到服务器的JavaScript事件的第一个问题,所以,自然而然,后者首先发生。此外,您还可以将客户端回调得到一个钩子的JavaScript时,Ajax响应已成功提交,通过指定的OnEvent 属性。

As of which event happens first question you need to understand that it is the JavaScript event that triggers sending of AJAX request to the server, so, naturally, the latter happens first. Also, you can attach a client side callback to get a hook to JavaScript when AJAX response has been successfully committed, by specifying onevent attribute.

这篇关于F:阿贾克斯由onchange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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