File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Quick question about getters and setters in Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Quick question about getters and setters in Struts 2" Watch "Quick question about getters and setters in Struts 2" New topic
Author

Quick question about getters and setters in Struts 2

Roberto Hernandez
Ranch Hand

Joined: Apr 29, 2009
Posts: 33
I'm working on a web project in struts 2. I have many actions, and each action has getters and setters to send/bring form values from request. Since many of my forms are similar, more often than not, I end up using same getters and setters but in several places.
I want to know how I can minimize redundant code in my application. Can the actions use something like an EJB that every action can share? or how else can I tackle this? Please help me!!! and if you know the answer please share an example
Thanks in advance!!!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Possibilities include using a base class, creating a base object with the repeated properties and using that in combination with action-specific properties, or using ModelDriven and a model (which could have a base class w/ shared properties) and extending it in the action with action-specific properties.

I'm sure there are other solutions too; those are the ones that popped immediately into my head.

Whether or not getters/setters fall under the category of "repeated code" is a little fuzzy for me, since it's basically non-code, usually automatically generated, and completely ignorable.
 
 
subject: Quick question about getters and setters in Struts 2
 
Similar Threads
struts 2 converter on Set data type
Topic: Struts and MVC. Question: how usually are working you?
How to tell where I came from?
Display tag + nothing found to display
Can I use the paramProperty from a hyperlink in a textfield in the called .jsp-page?