Print Shortlink

A Simple example of using DirectJNgine

During the Struts days, there was a library called DwR (Direct Web Remoting) that was popularly used to access the Java classes directly from JavaScript. DwR provided a JavaScript wrapper for the server side Java classes, so the code will look as if you’re directly calling the Java code from JavaScript.

A similar concept in Ext JS 4 is the pack. It provides you a facility to invoke the Java classes directly from Ext JS 4 code. There are multiple implementations of Ext direct available. One such implementation is DirectJNgine. DirectJNgine provides the infrastructure to invoke the Java classes directly from Ext JS 4 API.

A server side Java class “WeatherReporter” that can be invoked from client is shown below. It is decorated with the annotations provided by DirectJNgine.

package com.durasoft;
import com.softwarementors.extjs.djn.config.annotations.DirectAction;
import com.softwarementors.extjs.djn.config.annotations.DirectMethod;

public class WeatherReporter {
	public String getTemperature(String city) {
		return "Temperature of " + city + " is " + (Math.random()*100);

The Ext JS 4 code that is used to invoke WeatherReporter’s getTemperature method is shown below.


There’s a JavaScript class WeatherReporter generated by the DirectJNgine facility. This class sends an AJAX request to a DirectJNgineServlet that actually invokes our Java class. The web.xml file is provided with all these configuration details.

The complete project created in Eclipse is available at

Leave a Reply