aspose file tools*
The moose likes Struts and the fly likes Action class in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Action class in Struts" Watch "Action class in Struts" New topic
Author

Action class in Struts

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hello,

I'm working on Struts.
I went through the existing code written by my team and they have written many static methods in the action class.
So is it a right thing to mention such things in the action class apart from 'execute()' method, also the execute method is also containing business logic.
Also, should an action class have only one method i.e. execute ? not even a static block ?

The code is working fine. But is it a right design approach ?

Please advise.


Thanks,
Pramod
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

What are those action methods doing? Are they doing something with the state of the request. If so it is a bad design.
In my humble opinion having static methods in action is not a good design.

Let us see what others think.


Ananth Chellathurai [Walk on software]
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Thanks Ananth.
I'd like to hear more reviews/suggestions.
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

Struts 1 or struts 2


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Struts 1.2
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
On average, how many human users does the application support? How many concurrent users are there at peak load time?
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hi Jimmy,
The app is meant for at least 25k+ users.
There are around 5k users at a time using that app.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
When you say "meant for", does these mean that the application is not in Production or has never been completed?

Has the application ever supported 25K users?

Has the application ever supported 5K concurrent users?
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hi Jimmy,

The application is meant for all employees of a huge company which has more than 50k users.
And we never checked how many concurrent users are supported as there is no limitation to that.

I'm using java in a tool which is used in "Identity and access management".
and the java code uses struts 1.2 framework.

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Are employees using the application today? If so, are there any problems?
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hi Jimmy,

Yes, the employees of a particular team do use that app and it will be extended to other depts soon.
There is no problem with the code during runtime.

I'm just asking from the design perspective.
Is it a proper design to have different static methods and a static block apart from the execute method in the action class in struts 1.2
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
If you wanted to switch over to using a different GUI, say a desktop application, how long would it take to get this working? What would your estimate be?
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

The app has over 20 jsp and few other complex things making use of eDirectory. I think 4 weeks should be fine.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
In order to support both the HTML GUI and the desktop GUI, would you have two copies of business logic, one for HTML and the other for desktop?
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

I don't think so.
Could you please tell me the point you want to make?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
If you wouldn't have two copies of business logic, are you saying that you would build the desktop GUI to use the Struts Action classes?
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

I have never used struts for desktop gui, so don't have any clue.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
On another note, are you able to test out business logic from a command-line using a simple Java class with a main method?

Or, when testing business logic, do you always have to have a web server running and need to use the application's HTML pages?
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hey Jimmy,
Can you ask all questions at a time?
So that I can talk to my team mates and tell you.
Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 211
pramod talekar wrote:Hello,

I'm working on Struts.
I went through the existing code written by my team and they have written many static methods in the action class.
So is it a right thing to mention such things in the action class apart from 'execute()' method, also the execute method is also containing business logic.
Also, should an action class have only one method i.e. execute ? not even a static block ?

The code is working fine. But is it a right design approach ?

Please advise.


When people go on coding for long time without paying attention features like re-usability, testability, scalability start getting compromised. Programmers focus on pushing the next feature/fix out of the door and management has no problem in that. Most of the projects go in this direction, nobody else is to blame but the work environment and human nature.

In general, no static methods should be there in Struts 2 Action classes. Most of the times, all you need are execute() method and setters/getters for domain objects or data to expose/receive. If code contains static methods or static variables in a Struts 2 action, something is wrong and same should be do-able using method parameters.


-Varun -
(My Blog) - Online Certifications - Webner Solutions
Ravindra B Pawar
Greenhorn

Joined: Jul 18, 2010
Posts: 9
Threading Model
Struts 1 Actions are singletons therefore they must be thread-safe because only one instance of a class handles all the requests for that Action. The singleton strategy restricts to Struts 1 Actions and requires extra care to make the action resources thread safe or synchronized while developing an application.

Struts 2 doesn't have thread-safety issues as Action objects are instantiated for each request. A servlet container generates many throw-away objects per request, and one more object does not impose a performance penalty or impact garbage collection.


and your question is about the struts 1.2
i feel using static methods will work fine
STATIC METHOD IS LIKE A METHOD WHICH IS NOT DEPENDENT ON THE INSTANCE VARIABLES IN THE CLASS
SO WE CAN PUT SOME GENERIC FUNCTIONALITY IN THAT METHOD RELATED TO THAT CLASS

I think those methods might be used by the some other classes so they are marked as static

hope this helps
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Well said Varun

And thanks Ravindra for sharing your view.

cheers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Action class in Struts