简体   繁体   English

Ajax如何在JSF上工作?

[英]How does Ajax work on JSF?

I am new to JSF, but I have some experience with ASP.NET and its Ajax features. 我是JSF的新手,但我对ASP.NET及其Ajax功能有一些经验。 I know that JSF has some Ajax tags that can do some duties with Ajax, but I wonder how it uses Ajax. 我知道JSF有一些Ajax标签,可以用Ajax做一些工作,但我想知道它是如何使用Ajax的。 Does it use something like ScriptManager in ASP.NET? 它在ASP.NET中使用类似ScriptManager的东西吗?

Whenever you use the JSF <f:ajax> tag, the jsf.js script will be auto-included in the HTML head. 每当使用JSF <f:ajax>标记时, jsf.js脚本将自动包含在HTML头中。 It will take care about all the ajax magic. 它会照顾所有的ajax魔法。 The on* attributes of the generated HTML elements will where necessary be altered that way so that it uses the ajax script rightly. 生成的HTML元素的on*属性将在必要时以这种方式进行更改,以便正确使用ajax脚本。 You don't need to worry about this all, all you need to do is to specify and use the JSF <f:ajax> tag as documented. 您无需担心这一切,您需要做的就是指定并使用JSF <f:ajax>标记。 You don't need to manually include and configure the script like as ASP.NET ScriptManager. 您不需要像ASP.NET ScriptManager那样手动包含和配置脚本。

Note that this only works when you use Facelets as view technology, not its ancient predecesor JSP. 请注意,这仅在您将Facelets用作视图技术时才有效,而不是其古老的前置JSP。 You also need to make sure that you've a <h:head> instead of plain HTML <head> in the master template, otherwise JSF won't be able to auto-include the jsf.js script. 您还需要确保在主模板中有一个<h:head>而不是纯HTML <head> ,否则JSF将无法自动包含jsf.js脚本。

All with all, JSF ultimately generates plain HTML. 总而言之,JSF最终生成纯HTML。 Just open page in browser, rightclick and View Source . 只需在浏览器中打开页面,右键单击并查看源代码 If you are well familiar with basic HTML and JS, everything will be obvious. 如果您熟悉基本的HTML和JS,一切都会很明显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM