Please follow the tutorial to create a new application, or download the binary distribution and copy to have a skeleton.
If you want to use the web remoting feature, just copy the buffalo-version.jar (and commons-logging.jar if not supplied) and buffalo.js. Please refer other documents using buffalo. If you need buffalo delegate you page flow, please split the page as the demo application. Please not miss the best practice to see if your application suitable for OPOA.
To uprage is quite easy.
To integrated with Spring is quite simple. First you need to make sure spring can be loaded successfully (using config servlet or context listener). Please refer Spring related documents for further infomation. After that, add a config bean into any of the spring configruation files like below:
<bean name="buffaloConfigBean" class="net.buffalo.service.BuffaloServiceConfigurer"> <property name="services"> <map> <entry key="testSpringService1"><ref bean="yourBeanId"/></entry> <!-- oterh entries... --> </map> </property> </bean>
That's it. When the application is started, buffalo will find this bean and load all services defined in the services property. There is no difference between the service comes from buffalo-service.properties and spring. buffalo client cook them the same way. :)
There is a Buffalo.Form.formToBean method from buffalo version 1.2.1, which can serialize a form to an object directly. You can see the Form demo in the demo application. Here we have a simple example showing how we transform a form to a net.buffalo.demo.form.User object.
var userObj = Buffalo.Form.formToBean("form1", "net.buffalo.demo.form.User"); buffalo.remoteCall("userService.createUser", [userObj], function(reply){ alert(reply.getResult().username); })
The serializing principal:
Buffalo support customized event when doing remoting call:
Event | Description | Parameter | Default Impl |
onLoading | when loading a request | true or false | a buffalo loading div will appear on top right of the screen |
onFinished | when finished the request | nothing | empty function |
onError | when there is an error (normally is 500 or 404 error) | xmlhttp object | a red div will displayed |
onException | when invoking a service, throws exception | Buffalo.Fault object | a yellow div will displayed |
onTimeout | when timeout, default is 10 seconds | nothing | alert("timeout") |
If you want to customize the events, You can
var buffalo = new Buffalo(endpoint, async, {onLoading: yourLoadingFunction, onError: yourErrorHanlder ...})
Or
buffaloInstance.events["onLoading"] = function(state) { if (state) { //displaying message ... } }
Buffalo support on way binding, which is, bind the javascript object value to html elements.
buffalo.bindReply(service, params, elementId)
Above code will try to make a remote call, and bind the reply result to the element directly. Or you can try Buffalo.Bind.bind(elementId, bindValue).
You need the buffalo-blank.html to enable this feature. The download binary contains this file.
<iframe src="buffalo-blank.html" id="buffalo-view-history-iframe" width="0" height="0" style="display:none;"></iframe>
When you want to swtich the view, use buffalo.switchView(viewName), buffalo will remember the history automatically. If you don't need this feature for some specified view, use buffalo.switchPart(...) to exculde. Please reade the JavaScript API for more.
From 2.0, You can get/set the session/cookie/context value very conveniently. Use the class RequestContext, you can have full control of those lifecycle values in a easier way.
// Get a thread-safe request context context = net.buffalo.request.RequestContext.getContext(); // Get session value Map session = context.getSession(); String username = (String)session.get("username"); // Update the session value, will refresh the session immediately session.put("username", "newUsername"); // cookie Map cookieMap = context.getCookie(); Cookie cookie = cookieMap.get("cookieName"); // update cookie Cookie c = new Cookie("name", "value"); cookieMap.put(c.getName(), c); // ServletContext Map application = context.getApplication(); Object value = application.get("key"); ...