2

I am developing contact manager in struts with options(add,delete,modify,print).

I am thinking to map multiple actions(map multiple actions to the same class struts 2.3) to the same class(ContactManager).

I want to know whether it is correct or whether there is need to write separate action for each action?

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Satish Kadu
  • 29
  • 1
  • 4

2 Answers2

2

One good way to go, imho , is to use one Action for every action you have to perform, each one extending its last-forked parent Actions, like:

BaseAction
|
|----------BaseReportAction
|          |----- ExcelReportAction
|          |----- PDFReportAction
|          |----- CSVReportAction
|
|
|----------BaseCRUDAction
|          |----- CreateAction
|          |----- ReadAction
|          |----- UpdateAction
|          |----- DeleteAction
|
|
|----------BaseAJAXAction
|          |----- ReadSessionCountdownAction
|          |----- CheckNewMailsAction
|

etc...

Every Action extended by others will share protected attributes / methods to the children.

Take a look at this: Changing parameters after bind in Struts 2

My 2 cents.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
0

I think you should use a single action. It is totally a good practice, after all they provided the facility to invoke different methods in the same Action class for a purpose! You can achieve something like this by including a wildcard which which can map your action name to appropriate method in Action class.Like this-

    <action name="abc*" method="{1}" />