Presentation is loading. Please wait.

Presentation is loading. Please wait.

Struts 2 Interceptors By, Srinivas Reddy.S www.JAVA9S.com.

Similar presentations


Presentation on theme: "Struts 2 Interceptors By, Srinivas Reddy.S www.JAVA9S.com."— Presentation transcript:

1 Struts 2 Interceptors By, Srinivas Reddy.S

2 Interceptors Separates the cross cutting concerns Pre Processing and Post processing. Manages the work flow.

3

4 Interceptor By Example A Login page A Successful login page with a link to authorized page

5 Interceptor by Example Redisplay the login page for wrong credentials Access the Authorized page directly with out logging should forward the login page

6 The interceptor class should implement the Interceptor interface. Implement the intercept method. Do the pre processing and if everything is ok, invoke the invocation.invoke() which will call the next component in queue. If something goes wrong, return a string based on which a result page will be picked and sent to the client. After the invocation.invoke(), write the post processing logic Creating an Interceptor

7 Important Interceptors in defaultStack servletConfig – Sets the context related objects like HttpServletRequest, HttpServletResponse, HttpSession and HttpServletContext to the action if the action class implements the ServletRequestAware, ServletResponseAware, SessionAware, ServletContextAware respectively

8 modelDriven – Sets the form bean declared by the action in the valuestack. – The action should implement the ModelDriven interface. Important Interceptors in defaultStack

9 staticParams Helps to set the values from the struts.xml to the properties of action instead of the request parameters. params Responsible for all the request parameters to be set to the properties of the action. conversionError Tries to covert the request parameters to primitive data types and if there are any errors, the field errors will be set. Important Interceptors in defaultStack

10 Validation Checks if the validationAware is implemented by action or validates by the validation framework and sets the validation errors. workflow Checks if there are any field errors or action errors and then decides to invoke the action or to re send the input page

11 Interceptors in defaultstack  Handles the result based on the exception.  Enables to have a different named parameter  Will set the request, response, session objects to the action class.  This interceptor calls prepare() on actions which implement Preperable  sets the locale specified in a session as the locale for the current action request  Helps to chain the actions.  Provides several different debugging screens to provide insight into the data behind the page  Allows profiling to be enabled or disabled via request parameters, when devMode is enabled.

12  An interceptor that enables scoped model-driven actions.  Watches for ModelDriven actions and adds the action's model on to the value stack  Helps in file upload.  Looks for a hidden identification field that specifies the original value of the checkbox.  This interceptor populates the action with the static parameters defined in the action configuration.  This interceptor sets all parameters on the value stack dojo\..* Interceptors in defaultstack

13  ConversionErrorInterceptor adds conversion errors from the ActionContext to the Action's field errors.  Validates the parameters input,back,cancel,browse  An interceptor that does some basic validation workflow before allowing the interceptor chain to continue input,back,cancel,browse Interceptors in defaultstack

14 Thank you Download PPT and example code from


Download ppt "Struts 2 Interceptors By, Srinivas Reddy.S www.JAVA9S.com."

Similar presentations


Ads by Google