DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Task Driven vs Event Driven on Struts 2 Action

Task Driven vs Event Driven on Struts 2 Action

Ronald Daniel user avatar by
Ronald Daniel
·
Jun. 02, 12 · Java Zone · Interview
Like (0)
Save
Tweet
5.68K Views

Join the DZone community and get the full member experience.

Join For Free

i had a job to design and develop a new framework for my own development team. we made the decision that we will adopt the struts 2 as my mvc framework.

yes i see the benefit from struts 2 very well, easy to implement and has so many features. until, my team member said “hey, i hate struts very much,  because i have to put many exception-handling and/or debugger inside many events/methods. can we use another framework? or just use the servlet mixed with the scriptlet?”

well i know his concern, it would be easy to read and maintain the code with their exception-handling when your code was still small, but along with the time, you will have your own trouble to maintain the code to stay in a good shape, believe  me, i have had this kind of experience before.

so, i think and try to find a better solution and lucky for me, i found the much better solution with the task-driven approach. maybe for some of you this approach will look like a tricky, but no problem as long as my team could gain a benefit from it and keep the code stay in healthy shape :) .

well, as a brief introduction for struts 2. this action code,perhaps, is the common way that almost every single struts 2 developer will do. as you can see, you can have many methods that indicates as an “event”

as you can see, i have the events/methods execute(), save(), fetch(), and delete() .

and you can see on the above code, that you have to do the exception-handling four times, one each method.  for me — and team — one is more than enough, easy to read and maintain the code, especially when exception occur.

now, my approach is to convert the familiarity of the event-driven into the task-driven.  so, i just have to add a new parameter that i gave name task , as a flagging parameter. in here i will have only 4 tasks to subtitute the 4 methods, “ execute “, “ save “, “ fetch ” and “ delete “.

implementing the code is easy, just put one extra attribute on the action code, i named it task.

and on the jsp, only add a minor change, and i will give you the comparison between the event-driven and task-driven .

as you can see the difference between those 2 slices of code. i dont know how about you, but i love the task-driven struts more than the event-driven. maybe it’s relative, the answer could be different for another developer, but the most important for me is now my developers are happier to use struts.

Task (computing) Event

Published at DZone with permission of Ronald Daniel, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Deploy Apache Kafka With Kubernetes
  • Applying Kappa Architecture to Make Data Available Where It Matters
  • Top 20 Git Commands With Examples
  • The Evolution of Configuration Management: IaC vs. GitOps

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo