TechnoBuzz

A Techno Blog, mainly about Java

Struts2 Trainings

One of the struts 2 sample applications is the Mailreader application which has training course via Struts from Square One site .

Building Web Applications
Building Struts 2 Applications [ Welcome] [More …]

Struts 2 components

Action Handler, Result Handler, Custom Tags

Interceptor : bring custom code into call stack

  • Timer Interceptor
  • Prepare (able) – If the Action implements Preparable, calls its prepare method.

value stack : stack of objects that expression language can pull from

  • Action instance pushed onto stack

Jumpstarting JUnit (More …)

Capturing Input(More …)

Validating Input (More …)

Request Lifecycle in Struts 2 applications

  • User Sends request: User sends a request to the server for some resource.
  • FilterDispatcher determines the appropriate action: The FilterDispatcher looks at the request and then determines the appropriate Action.
  • Interceptors are applied: Interceptors configured for applying the common functionalities such as workflow, validation, file upload etc. are automatically applied to the request.
  • Execution of Action: Then the action method is executed to perform the database related operations like storing or retrieving the data from database.
  • Output rendering: Then the Result render the output.
  • Return of Request: Then the request returns through the interceptors in the reverse order. The returning request allows us to perform the clean-up or additional processing.

Display the result to user: Finally the control is returned to the servlet container, which sends the output to the user browser.
Struts 2 Big Picture

The diagram depicts the architecture of Struts 2 Framework. It shows the the initial request goes to the Servlet container, which is then passed through a standard filer chain.

  1. ActionContextCleanUp filter: The ActionContextCleanUp filter is optional. It is useful when integrating other technologies such as SiteMesh Plugin.
  2. FilterDispatcher: the required FilterDispatcher is called, which in turn consults the ActionMapper to determine if the request should invoke an action. If the ActionMapper determines that an Action should be invoked, the FilterDispatcher delegates control to the ActionProxy.
  3. ActionProxy: The ActionProxy consults the Configuration Files manager, which is initialized via the struts.xml file. Then the ActionProxy creates an ActionInvocation, which implements the command pattern. The ActionInvocation process invokes the Interceptors (if configured) and then invokes the action.
  4. Once the Action returns, the ActionInvocation is responsible for looking up the proper result associated with the Action result code mapped in struts.xml. The result is then executed, which often (but not always, as is the case for Action Chaining) involves a template written in JSP or FreeMarker to be rendered. While rendering, the templates can use the Struts Tags provided by the framework. Some of those components will work with the ActionMapper to render proper URLs for additional requests.
  5. Then the Interceptors are executed again in reverse order. Finally the response returns through the filters configured in web.xml file.
  6. If the ActionContextCleanUp filter is configured, the FilterDispatcher does not clean the ThreadLocal ActionContext. If the ActionContextCleanUp filter is not present then the FilterDispatcher will cleanup all the ThreadLocals present.

Resources

If you install the war on an application server (like tomcat ) you can easily run the sample projtect. Here is the struts 201 slides

Th version I have of the application mentions: “For more about the MailReader, including alternate implementations and a set of formal Use Cases, please visit the Struts University MailReader site” .

The full source code for MailReader is available as svn site, binaries, nightlies

Other Struts2 Trainings include Migrating to Struts2 the and JPA .

REFERENCES:

December 2, 2007 Posted by | AJAX, Struts | 1 Comment

web 2.0 conference

In Raleigh, I got a chance to attend IBM’s technical briefing on web 2.0 .

For now, will just list various bits of info that I will organize later.

QEDWiki (Quick and easy design) . Assembly : “QEDWiki is a unique Wiki framework in that it provides both Web users and developers with a single Web application framework for hosting and developing a broad range of Web 2.0 applications.”

Damia . Feeds: “provides easy-to-use tools that developers and IT users alike can use to quickly assemble data feeds from the Internet and a variety of enterprise data sources. The benefits of this service include the ability to aggregate and transform a wide variety of data or content feeds, which can be used in enterprise mashups.”

Mashup Hub. Tag : “Mashup Hub provides two broad areas of support: feed generation for enterprise data sources and a catalog of feeds and user interface (UI) widgets.”

Info 2.0

Many eyes

Baby name wizard

gather.com

second life

strike iron

gold corp

zoho

zoot

September 14, 2007 Posted by | AJAX, Blogging, J2EE, NC, Open Source, SOA, Web/Tech | Leave a comment

Speak Dojo

what is dojo?

Dojo is an Open Source JavaScript UI toolkit. It makes writing JavaScript easier, building great interfaces faster, and deploying dynamic UIs at scale much easier. The foundation of Dojo is “Dojo Base”, a single tiny library which contains Ajax, event handling, effects, blazing fast CSS queries, language utilities, and a lot more. On top of this Base, the rest of Dojo Core adds high-quality facilities for Drag and Drop, extended forms of Ajax and I/O, JSON-RPC, internationalization, and back-button handling.

You can use the div tag to define widget locations and Dojo will place the widget there either during page load or in response to events.

dojo book 0.4APIreference documentationDojo jot wikidojo toolkit home

JavaPassion PDF has 86 pages of info.

What is JSON?

(Using Dojo and JSON to Build Ajax Applications article ) – JSON is a Java library that helps convert Java objects into a string representation. This string, when eval()ed in JavaScript, produces an array that contains all of the information that the Java object contained. JSONObject class , JSONArray class “- Dojo provides an abstraction layer for invoking JSON-RPC requests”

json over xml?

IBM Paper: “JSON is built on two structures:

  1. A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  2. An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence

JSON-RPC is a lightweight remote procedure call protocol in which JSON serializes requests and responses

The request is a single object with three properties:

  • method – A string containing the name of the method to be invoked.
  • params – An array of objects to pass as arguments to the method.
  • id – The request ID. This can be of any type. It is used to match the response with the request that it is replying to.

When the method invocation completes, the service must reply with a response. The response is a single object with three properties:

  • result – The object that was returned by the invoked method. This must be null, in case there was an error invoking the method.
  • error – An error object if there was an error invoking the method. It must be null, if there was no error.
  • id – This must be the same ID as the request it is responding to.

A notification is a special request that does not have a response. It has the same properties as the request object with one exception:

id – Must be null

Using Dojo and JSON to Build Ajax Applications article: Dojo libraries are organized in packages just like Java code. For this example, we will need to import two packages.

The dojo.io package contains classes that allow us to make HTTP requests using protocols such as XMLHTTPTransport.

The dojo.event package is designed to provide a unified event system for DOM and programmatic events.

The dojo.event.connect() method allows you to associate a handler for the onclick event for myButton:

function onLoad() {

   var buttonObj = document.getElementById("myButton");

   dojo.event.connect(buttonObj, "onclick",

          this, "onclick_myButton");

  }  function onclick_myButton() {

   var bindArgs = {

    url: "welcome.jsp",

    error: function(type, data, evt){

     alert("An error occurred.");

    },

    load: function(type, data, evt){

     alert(data);

    },

    mimetype: "text/plain",

    formNode: document.getElementById("myForm")

   };

   dojo.io.bind(bindArgs);

  }

The magical dojo.io.bind() function is where the power lies. It takes as argument bindArgs, an array of name/value pairs. In this example, we specify five pairs:

  1. url: The URL to make the request to.
  2. mimetype: The response type expected.
  3. load: Code to execute upon success.
  4. error: Code to execute upon error.
  5. formNode: The ID of the form whose fields to submit as parameters to the URL.

Once the call to dojo.io.bind(bindArgs) is made,depending on whether the request encountered any errors, either the load or error code is executed. Both load and error take three arguments:
type
: The type of function; it will always be set to load for load() and error for error().
data
: The response received. If mimetype is specified as text/plain, data contains the raw response. If, however, text/json is used, data contains the value of eval('(' + responseReceived + ')'), where responseReceived is what the call returned.

evt: The event object.

July 21, 2007 Posted by | AJAX | Leave a comment

AJAX Roundup

AJAX: It enhances user interaction by targeting updates from the server
to specific areas of the web page, known as "In-page replacement" . DWR is easy AJAX for Java

Introduction where I learned of Jesse James Garrett  from  web site Adaptivepath.com is the person who is behind the technology.

AJAX w Java

Google Maps mania

AJAXIAN

Relevance has Demo from Ajax presentation at Java in Action .

Sun Tip on AJAX

AJAX Talk notes

Eclipse AJAX Toolkit Framework project

Paul Graham : "Basically, what "Ajax" means is "Javascript now works." And that in turn means
that web-based applications can now be made to work much more like desktop ones.

Similarly, RMH tunes in about AJAX

 

Google Maps

Stu Halloway : "predicts Ajax will be part of nearly all web applications within the next year."

Google Web Toolkit (GWT) this API  &samples Designer  Tool

Software Development in the Real World: The Complete List of Ajax Tools
(tags: ajax)

November 11, 2006 Posted by | AJAX | Leave a comment