Ajax4jsf User Guide-use Ajax in JSF

Source: Internet
Author: User
Ajax4jsf user guide Chinese Translation
Http://bbs.hexiao.cn/read.php? FID = 3 & tid = 13 & fpage = 1

Preface

Ajax4jsf is an easy-to-use framework. Its User Guide details how to use its functions. Learn more in time, and translate it to deepen understanding and facilitate more java enthusiasts to use the ajax4jsf framework.

Translation progress and problems can be discussed in the forum. http://bbs.hexiao.cn/

Chapter 2 is a simple introductionProgramAfter reading this chapter, you can create a basic Ajax program.
Chapter 2. Getting started with ajax4jsf

Environment requirements
To use the ajax4jsf framework, you only need jdk1.4 or higher, any JSF implementation, and your favorite servlet container. In the next chapter, we will provide you with detailed environment information.
Ajax4jsf is designed as an easy-to-use framework. You can use Ajax in your JSF program with only a few simple setup steps.

Download ajax4jsf
The latest ajax4jsf release is here

Https://ajax4jsf.dev.java.net/nonav/ajax/ajax-jsf/download.html

Download.
Install
Decompress the ajax4jsf.zip file.
Copy the ajax4jsf. jar and oscache-2.2.jar to the WEB-INF/lib folder of the program.
Add the following content to your program's WEB-INF/Web. xml file:

    • <Filter> <display-Name> ajax4jsf filter </display-Name> <filter-Name> ajax4jsf </filter-Name> <filter-class> Org. ajax4jsf. filter </filter-class> </filter> <filter-mapping> <filter-Name> ajax4jsf </filter-Name> <servlet-Name> faces servlet </servlet-name> <dispatcher> request </dispatcher> <dispatcher> forward </dispatcher> <dispatcher> include </dispatcher> </filter-mapping>

      Note: You can copy and paste the above content in the readme.txt file.

    • Add the following content:

      <% @ Taglib uri = "https://ajax4jsf.dev.java.net/ajax" prefix = "a4j" %>

      Go to every JSP page that uses Ajax.

Simple Ajax echo Project

Let's look at a simple JSF project. We only need a JSP page, which contains a form and some JSF labels:

Our simple program should allow us to input some text to

JSP page

Below is a page we needCode(Echo. jsp ):

<% @ Taglib uri = "https://ajax4jsf.dev.java.net/ajax" prefix = "a4j" %> <% @ taglib uri = "http://java.sun.com/jsf/html" prefix = "H" %> <% @ taglib uri = "http://java.sun.com/jsf/core "prefix =" F "%> <HTML>  

As you can see, the only line that is often different from the JSF Page code is the following line.

 
<A4j: support event = "onkeyup" rerender = "Rep"/>

Here we add an Ajax support in the parent tag (

<A4j: Support> the "rerender" attribute of the tag defines which part of our page is updated. here, the only updated part of the page is the

Data Bean

Of course, to run this program, we also need a managed Bean

 
Package demo; public class bean {private string text; Public Bean () {} Public String gettext () {return text;} public void settext (string text) {This. TEXT = text ;}}
Faces-config.xml

Next, we need to register the above bean in the faces-config.xml:

<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype faces-config public "-// Sun Microsystems, Inc. // DTD assumerver faces config 1.1 // en "" http://java.sun.com/dtd/web-facesconfig_1_1.dtd "> <faces-config> <managed-bean-Name> bean </managed-bean-name> <managed-bean-class> demo. bean </managed-bean-class> <managed-bean-scope> request </managed-bean-scope> <managed-property> <property-Name> text </property- name> <value/> </managed-property> </managed-bean> </faces-config>

Note: Nothing is directly associated with ajax4jsf.

Web. xml

Finally, do not forget to add the JAR file and change the Web. xml file:

<? XML version = "1.0"?> <Web-app version = "2.4" xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-Name> a4jechotext </display-Name> <context-param> <param-Name> javax. faces. state_saving_method </param-Name> <param-value> server </param-value> </context-param> <filter> <displa Y-Name> ajax4jsf filter </display-Name> <filter-Name> ajax4jsf </filter-Name> <filter-class> Org. ajax4jsf. filter </filter-class> </filter> <filter-mapping> <filter-Name> ajax4jsf </filter-Name> <servlet-Name> faces servlet </servlet-name> <dispatcher> request </dispatcher> <dispatcher> forward </dispatcher> <dispatcher> include </dispatcher> </filter-mapping> <listener-class> com. sun. faces. config. confi Gurelistener </listener-class> </listener> <! -- Faces servlet --> <servlet-Name> faces servlet </servlet-Name> <servlet-class> javax. faces. webapp. facesservlet </servlet-class> <load-on-startup> 1 </load-on-startup> </servlet> <! -- Faces Servlet Mapping --> <servlet-mapping> <servlet-Name> faces servlet </servlet-Name> <URL-pattern> *. JSF </url-pattern> </servlet-mapping> <login-config> <auth-method> basic </auth-method> </login-config> </Web- APP>

Now your program is ready to work.

Deployment

Finally, you can deploy your program in the servlet container. deploy the service in your desired container, and enter http: // localhost: 8080/a4jechotext/ECHO in your browser. JSF

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.