JSF - Ajax
来源:互联网 发布:在线编程怎么用 编辑:程序博客网 时间:2024/04/29 21:45
Ajax: A Brief Introduction
AJAX stands for Asynchronous JavaScript And Xml.
Ajax is a technique to use HTTPXMLObject of JavaScript to send data to server and receive data from server asynchronously.
So using Ajax technique, javascript code exchanges data with server, updates parts of web page without reloading the whole page.
JSF provides execellent support for making ajax call. It provides f:ajax tag to handle ajax calls.
JSF Tag
<f:ajax execute="input-component-name" render="output-component-name" />
Tag Attributes
If true, the Ajax behavior will be applied to any parent or child components. If false, the Ajax behavior will be disabled.
2eventThe event that will invoke Ajax requests, for example "click", "change", "blur", "keypress", etc.
3executeA space-separated List of IDs for components that should be included in the Ajax request.
4immediateIf "true" behavior events generated from this behavior are broadcast during Apply Request Values phase. Otherwise, the events will be broadcast during Invoke Applications phase
5listenerAn EL expression for a method in a backing bean to be called during the Ajax request.
6onerrorThe name of a JavaScript callback function that will be invoked if there is an error during the Ajax request
7oneventThe name of a JavaScript callback function that will be invoked to handle UI events.
8renderA space-separated list of IDs for components that will be updated after an Ajax request.
Example Application
Let us create a test JSF application to test the custom component in JSF.
UserData.java
package com.tutorialspoint.test;import java.io.Serializable;import javax.faces.bean.ManagedBean;import javax.faces.bean.SessionScoped;@ManagedBean(name = "userData", eager = true)@SessionScopedpublic class UserData implements Serializable { private static final long serialVersionUID = 1L; private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getWelcomeMessage(){ return "Hello " + name; }}
home.xhtml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:tp="http://java.sun.com/jsf/composite/tutorialspoint"> <h:head> <title>JSF tutorial</title> </h:head> <h:body> <h2>Ajax Example</h2> <h:form> <h:inputText id="inputName" value="#{userData.name}"></h:inputText> <h:commandButton value="Show Message"> <f:ajax execute="inputName" render="outputMessage" /> </h:commandButton> <h2><h:outputText id="outputMessage" value="#{userData.welcomeMessage !=null ? userData.welcomeMessage : ''}" /></h2> </h:form> </h:body></html>Once you are ready with all the changes done, let us compile and run the application as we did in JSF - First Application chapter. If everything is fine with your application, this will produce following result:
Enter name and press Show Message button. You will see the following result without page refresh/form submit.
- JSF - Ajax
- JSF+Ajax专题
- JSF之AJAX学习
- JSF学习五Ajax
- 关于JSF ajax 提交
- JSF探索--ajax应用
- jsf中的ajax技术
- jsf大将之ajax
- Ajax和JSF
- JSF中的Ajax
- Ajax优于JSF的原因
- Apusic JSF — 体验Ajax
- asp.net ajax Vs jsf
- Ajax Integration with JSF 2.0
- JSF简单的ajax事件
- JSF教程(3)——初探JSF中的Ajax
- 开始为exoplatform实现ajax-jsf组件。
- 在JSF中如何使用AJAX
- 【SPOJ-TOMJERRY】Tom and Jerry【概率DP】【记忆化搜索】
- 地图之美(一)——帅爆了!!!
- Chapter2 使用Web容器
- FPGA 入门 (一)
- win7下eclipse插件连接linux下hdfs单机伪集群 hadoop 2.6
- JSF - Ajax
- shell执行方式备忘
- 基于Hadoop的大数据平台实施记——整体架构设计
- Linux常用命令
- cocos2d unity3d 获取访问文件列表(一)
- 网络流
- sql的优化相关问题
- oracle实现分页与mysql实现分页功能
- 错排问题,错位排列