CSS Drop Down Menu

Sunday, 19 January 2014

Struts2.x: Core Component

Core Components Of Struts2.x :-

[1]- Interceptors
[2]- ValueStack
[3]- ActionContext
[4]- ActionInvocation
[5]- OGNL

[1]-Interceptors :-

Interceptor is an object that is invoked at the preprocessing and postprocessing of a request. In Struts 2, interceptor is used to

perform operations such as validation, exception handling, internationalization, displaying intermediate result etc.

Advantage of interceptors :-

Pluggable If we need to remove any concern such as validation, exception handling, logging etc. from the application, we don't need to

redeploy the application. We only need to remove the entry from the struts.xml file.

Struts 2 default Interceptors :-

There are many interceptors provided by struts 2 framework. We have option to create our own interceptors. The struts 2 default interceptors are as follows:
[1]- alias It converts similar parameters that have different names between requests.
[2]- chainIf it is used with chain result type, it makes the properties of previous action available in the current action.
[3]- cookie It adds a cookie to the current action.
[4]- createSession It creates and HttpSession object if it doesn't exists.
[5]- clearSession I It unbinds the HttpSession object.
[6]- execAndWait It sends an intermediate waiting page for the result.
[7]- exception It maps exception to a result.
[8]- fileUpload It provides support to file upload in struts 2.x
[9]- i18n It provides support to internationalization and localization.
[10]- i18n It provides support to internationalization and localization.
[11]- logger It outputs the action name.
[12]- params It populates the action properties with the request parameters.
[13]- roles It supports role-based action.
[14]- scope It is used to store the action state in the session or application scope.
[15]- servletConfig It provides access to maps representing HttpServletRequest and HttpServletResponse.
[16]- staticParams It maps static properties to action properties.
[17]- timer It outputs the time needed to execute an action.
[18]- validation It provides support to input validation.
[19]- workflow It calls the validate method of action class if action class implements Validateable interface.

[2]- Struts2 ValueStack :-

A valueStack is simply a stack that contains application specific objects such as action objects and other model object. At the

execution time, action is placed on the top of the stack. We can put objects in the valuestack, query it and delete it. The value stack

can be accessed via the tags provided for JSP, Velocity or Freemarker. There are various tags which we will study in separate

chapters, are used to get and set struts 2.0 value stack. You can get valueStack object inside your action as follows:

[3]- ActionContext :-

The ActionContext is a container of objects in which action is executed. The values stored in the ActionContext are unique per

thread (i.e. ThreadLocal). So we don't need to make our action thread safe. We can get the reference of ActionContext by calling

the getContext()
method of ActionContext class. It is a static factory method. For example:

[4]- ActionInvocation :-

The struts framework provides ActionInvocation interface to deal with ActionInvocation. It provides many methods, some of them can be used to get the instance of ValueStack, ActionProxy, ActionContext, Result etc. The ActionInvocation represents the execution state of an action. It holds the action and interceptors objects.

[5]-OGNL :-

The Object-Graph Navigation Language (OGNL) is a powerful expression language that is used to reference and manipulate data on the ValueStack. OGNL also helps in data transfer and type conversion. The OGNL is very similar to the JSP Expression Language. OGNL is based on the idea of having a root or default object within the context. The properties of the default or root object can be referenced using the markup notation, which is the pound symbol(#). [The symbol (#) for a pound as a unit of weight..] As mentioned earlier, OGNL is based on a context and Struts builds an ActionContext map for use with OGNL. The ActionContext map consists of the following:-
application - application scoped variables
session - session scoped variables
root / value stack - all your action variables are stored here
request - request scoped variables
parameters - request parameters
atributes - the attributes stored in page, request, session and application scope
It is important to understand that the Action object is always available in the value stack. So, therefore if your Action object has properties x and y there are readily available for you to use. Objects in the ActionContext are referred using the pound symbol(#), however, the objects in the value stack can be directly referenced, for example if employee is a property of an action class then it can ge referenced as follows:
instead of

0 comments:

Post a Comment