In what cases is better to use DispatchActions than Action?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you need many similar actions with similar form bean in the same struts module (e.g. CRUD actions to
createreadupdatedeletethe same object). With plainActionyou’ll need 4 Struts action files with imports, headers, method signatures:Also you’ll need 4 action mappings in
struts-config.xml(of course if you are not using annotations). But in fact they will just invoke the next layer of code (manager/DAO/etc), which is independent from web (from request/response/mapping classes) and thus testable with unit tests allowing test-driven development and code reusability. All four classes will differ only in 1-2 lines of code. The rest is boilerplate, repeating again and again.By adding additional parameters or reusing existing one in HTTP request (in other words: in JSP form tag) you can pack all 4 actions in one class, e.g. in
EventDispatchAction:This requires much less boilerplate. In order to tell which action you want to perform, you can use submit buttons: