|
|
Best Practices
-
You can get access to Http Session, Http Request and Application context Objects using ActionContext object. The
preferred way in Struts2 is to use the Aware interfaces, like SessionAware, HttpRequestAware and ApplicationAware.
There is an special scope in Struts2 which is called Action context and you can access values stored under that scope on a web
page
by prefixing the name of the variable with '#' symbol, e.g. #variable. Use #session.variable, #request.variable on pages to
get the values from variables under scopes.
-
Use Spring framework's plugin for Struts to create actions with dependencies using the Spring context. That will save
you time and effort to have classes ready for use. Also that is a best practice to initialize the actions and other
objects with dependencies at the time of web application loading. You can use Spring's context listener along with
the web application context utility to put objects in the web application context for future application-wise use.
-
Do not use ajax tags unnecessarily, be judgemental in using the ajax tags. Because ajax tags do not come without cost.
Actually they make calls to web servers just like any other actions. If you invoke too many ajax call from the same page,
the response for that page may deteriorate. This is quite possible when you are making automatic calls using the timer in your
ajax tags. Also sometimes when you do not know the internals of a page which has been already developed by others,
you may invoke some ajax calls which may conflict with other ajax or action calls, if action call and ajax call is
happening at the same time. You have to know internals of the page design in
such a situation. Also keep in mind that when you are using ajax tags, they use Dojo or other javascript bundles behind the
scene. Those bundles are heavy weight, those may load too many scripts which are not directly used by your call,
and that sometimes causes performance issues.
|
|