Why do I need a prep interface in Struts2?

We have an Interceptor, we have a custom interceptor where we can do whatever we want to do before or after our action.
Then what is the need to use the prepared interface and implement the method of preparation for it?
Is this another option, or is there any specific goal?

+6
source share
2 answers

A well-prepared interface works in conjunction with the Prepare Interceptor. This interface has one method defined by prepare() , and since its name suggests that this method is responsible for preparing the action.

Prepare the prepare() interceptor calls for activities that the Prep implementation implements. This interceptor is very useful for any situation where you need to ensure that some logical tasks are completed before the actual execution method is executed. Therefore, if you see that this is some kind, if init for your action class, and it ensures that another method is called before the action is executed, or by any method, this method allows your execution method to work fine.

If you see the default definition in the kernel, you will find out that this hook is called before params or the workflow hook, which indicates its purpose.

A typical use of this is to run some logic to load an object from the database so that when setting parameters, they can be installed on this object. Read more in the Prep Interceptor document to find out how it works in close collaboration with the prepared interface. In short. Prepare the interceptor to act only when the action implements the Preparatory.

Prepare-interceptor

+8
source

Preparing the interface ensures that if the used object is already on the value stack, then there is no need to query the database, it fills out the form properties using the existing object on the value stack.

0
source

Source: https://habr.com/ru/post/908409/


All Articles