Services | Updates | Contact
Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
Overview of the POI APIs
Jakarta POI Jakarta provides Jakarta POI APIs for manipulation of various file formats based upon Microsoft's OLE 2 Com
 
Open Source Download Manager
A download manager is a computer program designed to download files from the Internet, unlike a web browser, which is ma
 
More Tutorials...


    Loan Information     Struts     Open Source

Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

 
 
Struts

 
Comments
 
 

 

Set the action name 

                         

2. Set the action name to the action attribute of html:link 

// eventdispatchaction.jsp 

<tr> 

<td> 

<html:link action="crudEventDispatchAction ?createAlias=create " ><b>C</b>reate an Employee record</html:link> 

</td> 

</tr> 

3. Either directly use the method name to call as a query string parameter, or use an alias. 

// eventdispatchaction.jsp ( Direct calling ) 

<tr> 

<td> 

<html:link action="crudEventDispatchAction? update "><b>U</b>pdate Employee details</html:link> 

</td> 

</tr> 

 

// eventdispatchaction.jsp ( Calling using an alias ) 

<tr> 

<td> 

<html:link action="crudEventDispatchAction? createAlias=create" ><b>C</b>reate an Employee record</html:link> 

</td> 

</tr> 

What are the advantages? 

  1. Events can be attached to controls directly. 

  2. No need to use a separate hidden variable or a query string for mapping the method name to the actual method to call. 

  3. Actual method to call can be aliased with a pseudo name. 

What are the disadvantages? 

  1. The need to extend the class from EventDispatchAction and hence cannot extend our class from a custom base class. 

EventActionDispatcher 

How to create one? 

  1. Extend your action from Action, similar to the case in ActionDispatcher. This is what is desirable for us.

// CRUDEventActionDispatcher.java 

/** 

* This is an example class for demonstrating EventActionDispatcher 

* functionality. Observe here that we can also extend our class from 

* BaseAction class like in ActionDispatcher example and move our 

* session validation to that class. 

* <p> 

* The EventActionDispatcher as the name suggests is used to attach 

* events to the html controls. This type of aggregation eliminates the 

* need to define a parameter(eg., methodToCall). We havent used any 

* hidden parameters to combine an event to a method. This event-to-method 

* mapping is removed using EventActionDispatcher. 



* We can also use an Alias for the method name and map it to the method name 

* as can be seen in the createAlias event. 



* @author Praveen Babu Kusuma 

* @version 1.0.0 



* http://www.javahome.co.nr 

* http://praveen.awardspace.com 

*/ 

public final class CRUDEventActionDispatcher extends Action { 

protected ActionDispatcher dispatcher = new EventActionDispatcher(this); 

public ActionForward execute(ActionMapping mapping, 

ActionForm form, 

HttpServletRequest request, 

HttpServletResponse response) throws Exception { 

// This method will handle the dispatching of the action to the appropriate method. 

System.out.println("I am in CRUDEventActionDispatcher - execute"); 

return dispatcher.execute(mapping, form, request, response); 



... 

2. Set the action name to the action attribute of html:link. 

// eventactiondispatcher.jsp 

<tr> 

<td> 

<html:link action =" crudEventActionDispatcher ?createAlias=create"><b>C</b>reate an Employee record</html:link> 

</td> 

</tr> 

3. Either directly use the method name to call as a query string parameter, or use an alias. 

// eventactiondispatcher.jsp ( Direct calling ) 

<tr> 

<td> 

<html:link action="crudEventActionDispatcher? delete "><b>D</b>elete Employee record</html:link> 

</td> 

</tr> 

 

// eventactiondispatcher.jsp ( Calling using an alias ) 

<tr> 

<td> 

<html:link action="crudEventActionDispatcher? createAlias=create "><b>C</b>reate an Employee record</html:link> 

</td> 

</tr> 

What are the advantages? 

  1. Events can be attached to controls directly. 

  2. No need to use a separate hidden variable or a query string for mapping the method name to the actual method to call. 

  3. Actual method to call can be aliased with a pseudo name. 

What are the disadvantages? 

1. None. 

Note that the use of true (read=true) while using the query string variable to specify the event name is optional. Also, note that this variable is different from the one we used earlier (methodToCall). Here we directly specify the event name or its alias not the variable name or the actual method to call. 

Assumptions 

  1. It is assumed that you have the complete source code of this discussion with you. 
             

  2. For some examples, I assume that our application is a full fledged web application wherein a user is authenticated before entry into the system and we are validating the user session in a base class. Why is this so important? Because, to use some types of aggregations, we should extend our action class from a specific subclass of Action. This restricts us from extending the action class from a custom base class. DispatchAction is an example of such an action. 
             

  3. It is assumed that all we are interested in are the Create, Read, Update and Delete operations on an entity in the database. These
    actions, also called CRUD actions, are the basis for all the examples of this discussion. 
            

  4. One more assumption is that it is assumed that we are interested in attaching events to the HTML controls, which you may be familiar in JSF, where in we attach events to the controls using action and actionListener attributes. 
            

  5. It is assumed that the examples provided depict only one way of usage. You are free to experiment with the code, like for instance, replacing query string with hidden variables. 

Source Code 

 Download

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.