Should the strut annotation @Result only be at the class level or not?

I read the Struts2 documentation and found that there was some kind of contradiction in its documentation. In this link https://struts.apache.org/docs/convention-plugin.html

The Convention plugin allows action classes to define different outcomes for an action. The results are divided into two categories: global and local. Global results are distributed among all actions defined in the action class. These results are defined as annotations for the class of actions. Local results apply only to the action method that they are defined on

However, another link https://struts.apache.org/docs/result-annotation.html suggests:

@Result annotations live at the Action class level, not at the method level. This matches what is in the XML-based Action configuration. Do not be tempted to comment on your actions. he will not work.

So which one is correct? Can @Result be defined at the method level?

+5
source share
1 answer

Local results are configured to configure actions using the @Action property. In other words, local results are tuned where they are allowed. Using the @Action annotation, you specify a list of results properties. Here you can add @Result annotations.

There is an excerpt from Dave Newtonโ€™s book Apache Struts 2 Web Application Development :

We can also customize the results with annotations to the Convention. We should not rely on the conceptual concept of the Convention that our result JSP files should be named. We can define the results manually using @Result and the @Results annotation if we need multiple Results. (We can use the @Results annotation only in the class, and the @Action and @Actions are available at the method level. We can define several results at the action level through the @Action annotation results property. )

Wiki definition is also correct

Global results are distributed among all actions defined in the action class. These results are defined as annotations for the class of actions. Local results apply only to the method of action that they are defined on . The following is an example of various types of result annotations:

com.example.actions.HelloWorld

 package com.example.actions; import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Actions; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; @Results({ @Result(name="failure", location="fail.jsp") }) public class HelloWorld extends ActionSupport { @Action(value="/different/url", results={@Result(name="success", location="http://struts.apache.org", type="redirect")} ) public String execute() { return SUCCESS; } @Action("/another/url") public String doSomething() { return SUCCESS; } } 
+3
source

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


All Articles