Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Urgent Dispatch Action

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
can anyone send me some sample code where a dispacthAction calls a business Delegate, which in turn calls the Business Compoenent .
Actually i am new to dispatchAction and Business Delegate.
Please help as its urgent.

Thanks
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Manish.. Try this simple example and I hope it'll help you.

Suppose you have a business logic component BooksDAO which has few methods like getAllBooks(...) and addBook(...) etc. Now in a view (say)books.jsp you hav links like View All Books, Add A Book, etc..
You can build those links like...
<html:link href="/manageBooks.do?page=view">View All Books</html:link>

Now write the following Action class ManageBooks.java


package pack1;
// imports
public class ManageBooks extends DispatchAction implements java.io.Serializable
{
public ActionForward view(ActionMapping mapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception
{
//Call the business logic getAllBooks() here
return mapping.findForward("view");
}

// Similarly we can put another method say add
public ActionForward add(ActionMapping mapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception
{
//Call the business logic addBook() here
return mapping.findForward("add");
}
}// End of class

--------------
Now in your struts-config.xml file write the following to invoke the dispatch actions

<action path="/manageBooks" type="pack1.ManageBooks"
scope="request" validate="false" parameter="page" input="books.jsp">
<forward name="view" path="/viewBooks.jsp" redirect="true"/>
<forward name="add" path="/addBooks.jsp" redirect="true"/>
</action>

Now in above action, the parameter attribute is important as according to it, the methods in the disptch action classes will be deligated.

regards,

Niranjan
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic