问题描述
我使用的应用程序,其中有JSF2框架。该框架的想法是管理后台(JAVA)和前端之间的连接。
I am working with the application, which has JSF2 framework. The idea of that framework is to manage connection between Backend (Java) and Frontend.
我知道,我们使用JSF版本创建的 jsf.ajax 的一个DOM,它拥有几种方法进行传递和获取数据对象。
I know, that JSF version we are using creates jsf.ajax object in a DOM, which holds several methods for performing passing and getting data.
于是,像我建立前端架构基于模块的模式有私人范围的每个。里面几个模块,我需要做的AJAX调用来从后端的一些数据,但如果我使用JSF的非标准方法调用的 A4J:jsFunction 的($ pviously方式创建p $),我失去范围我的JavaScript模块立即。当然,不能返回到模块
And so, as I am building Frontend architecture based on modules pattern which has private scope each. Inside several modules I need to make AJAX call to get some data from Backend, but if I am using standart way of JSF by calling a4j:jsFunction (previously created), I am loosing the scope of my JavaScript module immediately. And, of course, can not return back to the module.
所以,我问的是,可以存档类似的东西来的 jQuery.ajax()的方法,使用的 jsf.ajax 的对象和它的方法(要求/效应初探)?!
Therefore, I am asking is that possible to archive something similar to jQuery.ajax() method by using jsf.ajax object and its methods (request/reponse)?!
jQuery.ajax({
url: "", // I don't have url as in PHP, I have JSF action listener #{method.function}
data: { param: 'value' }, // params for method.function
success: function(data){
// yes I need to receive the data from Backend (maybe #{bean} or JSON)
}
});
我坚信,有一种方法来使用JSF和AJAX的Java(A4J)存档我需要通过保持的JavaScript模块的范围内,没有走出去,当使AJAX调用。
I strongly believe, there's a way to use JSF and AJAX for Java (A4J) to archive my need by keeping a scope of JavaScript module, without going out of that when making AJAX calls.
推荐答案
如果你需要一个AJAX组件从服务器上传/检索任意数据,那么我不认为jsf.ajax是适合你的工具。这是严格耦合到JSF presentation和可以用来调用服务器逻辑和呈现的HTML页面的部件。响应将与局部更新的XML。下面我将介绍如何弯曲对你的目的,但它不会被有意申请该API的。
If you need an ajax component to post/retrieve arbitrary data from the server then I don't think jsf.ajax is the right tool for you. It is strictly coupled to the JSF presentation and can be used to invoke the server logic and render parts of the html page. The response will be an XML with partial-updates. Below I will describe how to bend it towards your purpose but it won't be intended application of this api.
总之这一切都被称为像:
In short this would have to be called like:
jsf.ajax.request(<DOM_node>, event, {render: "<rendered_id>", execute: "@this"})
在哪里DOM_node是元素它有一个动作监听器,事件的类型是由听众的支持(如果你使用jsf.ajax.request作为的onclick然后只是事件变量将可用,你可以把它作为是JS事件)。 &LT; rendered_id&GT;应该是JSF组件的客户端ID周边要作为一个回调来执行脚本。
Where DOM_node is element which has an action listener, event is JS event of type supported by the listener (if you use jsf.ajax.request as onclick then just "event" variable will be available and you can pass it as is). <rendered_id> should be client id of JSF component surrounding the script you want to execute as a callback.
的结果调用应要求JSF执行附加到对应DOM_node组件动作监听器(如commandLink),并重新呈现区域以&lt包含组件内; rendered_id取代。如果它包含HTML&LT;脚本&GT;标签,该脚本将被执行。它可以包含你的JSON数据和函数调用。
The resulting call should ask JSF to execute action listener attached to component corresponding to DOM_node (like commandLink) and rerender area contained within component with <rendered_id>. If it contains html <script> tag, this script will be executed. It can contain your JSON data and function calls.
下面是链接到文档。
这篇关于使用JSF AJAX方法,以保持JavaScript的模块范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!