Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Struts2 Results annotations override or add to superclass defined values?

The following example: I have a superclass and subclass for a struts action. The superclass defines @Results, and the subclass needs to define additional specific @Result entries. For example:

@Results({
    @Result(name=BaseAction.ERROR, location="/WEB-INF/jsp/error.jsp")
})
public abstract class BaseAction extends ActionSupport implements ServletRequestAware {
    ...
}

..and a subclass

@Results({
    @Result(name=BaseAction.INDEX, location="/WEB-INF/jsp/reporting/index.jsp")
})
public class ReportAction extends BaseAction {
    ...
}

My question is, does an instance of ReportAction only have the @Result of INDEX defined, or does it also contain any @Result entries defined in any if it's superclasses. Is my ReportAction aware of the location set for BaseAction.ERROR ??

Thanks, Martin

like image 911
uncrase Avatar asked Sep 26 '11 13:09

uncrase


People also ask

Which is default result type in struts2?

The dispatcher result type is the default type, and is used if no other result type is specified. It's used to forward to a servlet, JSP, HTML page, and so on, on the server.

What is Execute method in struts2?

The method execute is where we placed what we want this controller to do in response to the hello. action . Method execute of HelloWorldAction. public String execute() throws Exception { messageStore = new MessageStore() ; helloCount++; return SUCCESS; }

What is ActionSupport in struts2?

ActionSupport class implements a no. of interfaces like Action, Validateable, LocaleProvider and Serializable etc. It is more commonly used instead of Action interface.


1 Answers

Yes, your ReportAction class will have both BaseAction.INDEX and BaseAction.ERROR.

General super class or sub class rule will apply in this case also. If you don't find something in your subclass it will go and look into the super class.

In your case BaseAction.ERROR not found in your subclass it will go and look into the superclass.

like image 116
Moni Avatar answered Oct 30 '22 01:10

Moni