Introduction of domestic Ajax framework-buffalo and quick-start __ajax

Source: Internet
Author: User
Tags serialization

Today, I read an article on CSDN. Domestic AJAX framework, go down to Buffalo's website to look, really good, document, Help, download, example all write very complete, some examples are in actual project development very practical, so here also do a brief introduction, Content mainly from the Buffalo website, I also is to do a collation, by the way to be a preacher (definitely not AH)

The content is divided into two parts, we can choose according to the need to see

1. Characteristics of the Buffalo

Ajax is starting to go a big way, and Sun's blueprints has begun to include Ajax support. However, it is not easy to program directly using XMLHTTP in most cases. Buffalo makes this process much easier. Buffalo first is a JavaScript implementation of the burlap protocol, but he provides more support for Amowa (Web applications for asynchronous messages)/ajax. Developers can use Buffalo to add Amowa/ajax features to Web applications, and as developers request, Buffalo gradually joins the web element, making buffalo progressively closer to a fully functional, new web framework. JavaScript implementation of Burlap protocol

In fact, the burlap protocol should be the most suitable communication protocol for use as a web remoting, comprehensive, concise and applicable. Buffalo implements JavaScript serialization/deserialization of most of the data types in the Burlap protocol. bidirectional serialization of Java objects to JavaScript objects full support

The result of any method invocation from the Java end can be transparently serialized to the JavaScript side, no matter how complex the object is, whether it is a simple atomic type (String, int, long, Boolean), or a complex object (List, Map), Even your own defined business object, Buffalo can serialize it to the JavaScript side, and you can interact with JavaScript. This feature of Buffalo has been proven to be its most characteristic feature. For example, Userservice.listall () returns the list of all users (java.util.List):

How the client is invoked:

Buffalo.remotecall ("Userservice.listall", [],function (Reply) {
//Don't worry, Reply.getresult will intelligently judge the result type of the server-side remote invocation.
var userlist = Reply.getresult (); 
var firstuserfamilyname = userlist[0].name.familyname;
};

programming model for asynchronous callbacks

Before Buffalo 1.1, each method call is asynchronous, and after version 1.1, Buffalo supports synchronous calls (although this is not recommended). The two programming models are exactly the same, and you may use the system's login function in this way:

var buffalo = new Buffalo ("/bfapp/buffalo"); The 1.2 version of the
Buffalo.remotecall ("Userservice.login", ["username", "password"], function (reply) {
    var success = Reply.getresult ();
    if (success) {
        alert ("You login Successfully");
    } else {
        alert ("User name or Password incorrect!");
    }
});

support for asynchronous events

Like Gmail, when loading the system, there is a small loading bar, instead of switching pages. Buffalo give you support. Onloading, OnFinish, OnError, you can define these events to fit the needs of your application. simple, intuitive, easy to use

Buffalo developers do their best to make the API design easy to use, whether on the client or server side, as much as possible without the developer to understand the buffalo details. server-side , using Buffalo developers, there is little need to understand the Java code structure of Buffalo. Any pojo can become a Buffalo service is exposed.

clients , developers only need to interact with one object: Buffalo, and only need to interact with a few methods. Any beginner can be familiar with buffalo within half an hour and begin to develop. Integrated prototype Library

Referring to the simple idea of Ruby, prototype provides simple and straightforward support for real web development. The Buffalo 1.2 version begins to be rewritten with prototype syntax and built directly on it because prototype can be used directly and can be of great benefit to web development with little learning. Spring Integration

Spring is currently the most popular lightweight container, and Buffalo supports it. Any of the configured beans in spring can be exposed to the Buffalo service through a simple configuration. Browser compatible

Buffalo currently supports Ie6/firefox 1.0+ browsers. Support browser forward/Back button

Many large areas of AJAX-enabled Web applications often fall into the trap of a browser's forward-backwards functionality. This problem was addressed in the Buffalo 1.2 release. As long as you add a buffalo-blank.html reference to the main page and use the Buffalo.switchview method, you will find that the browser's forward back button is available and can be navigated correctly. support for data binding

For general data Return values, Buffalo provides a binding capability to quickly bind the value of a JavaScript object to an HTML element. The bound element supports text, checkbox, Radio, textarea, select, Span/div, table.

2. Quick Start

1. Download Buffalo 2. Web application directory 3. Editor Web.xml 4. Editor Buffalo-service.properties 5. Edit JSP file 6. Editor Helloservice.java 7. Run

This article will be for the first contact Buffalo developers, to provide a one-minute quick tutorial, so that development can quickly grasp the development of buffalo. Any tutorial is starting with Hello, world, and we are no exception. In order to demonstrate the basic functions of buffalo and how to use Buffalo, there seems to be no simpler example than this ~ 1. Download Buffalo

please download the latest version in the download page. You can also skip this article, download Buffalo-example.war directly, in that package, already contains the configured Buffalo, as well as the demo application involved in this article. 2. Web application directory

+ buffalo-example
       web-inf/classes
       web-inf/lib
       Script

then place the Burlap-2.1.2.jar, Buffalo-<version>.jar in the Web-inf/lib, and Prototype.js, buffalo.js into the script directory. 3. Editor Web.xml

Create a new web.xml, put it in the Web-inf, and edit the contents as follows:

<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE Web-app Public "-sun Microsystems, INC.DTD Web Application 2.3//en" ">
<web-app>
< Display-name>buffalo Example application</display-name>
<servlet>
    <servlet-name> Bfapp</servlet-name>
    <servlet-class>net.buffalo.web.servlet.applicationservlet</ servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>bfapp</ servlet-name>
    <url-pattern>/bfapp/*</url-pattern>
</servlet-mapping>
</ Web-app>

4. Editor Buffalo-service.properties

Creates a new empty text file, named Buffalo-service.properties, and places it in the Web-inf/classes, edited as follows:

# Example Service
helloservice=example. HelloService

5. Edit JSP file

Create a new empty HTML file, named example.jsp, below the root directory, as follows:

6. Editor Helloservice.java

package example;
public class HelloService {public
string Hello (string name) {
  try {
    //to] the loading div
    Thread.slee P (PS);
  } catch (Interruptedexception e) {
    e.printstacktrace ();
  }
  Return "Hello," + name;
  }
}

compile and put the compiled class under Web-inf/classes. 7. Run

Copy the entire folder of Buffalo-example to Tomcat_home/webapps, start Tomcat, open the browser, and then typing http://localhost:8080/buffalo-example/ Example.jsp, you should be able to see the following screen:

After clicking the "Hello" button

Wait a minute, 2 seconds later:

If the operation succeeds, you are successful in running the first Buffalo supported Web application.

Refer to the application in the demo for further understanding of Buffalo.

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.