• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Urgent Dispatch Action

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic