开发者

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

开发者 https://www.devze.com 2023-04-08 23:53 出处:网络
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:

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 th开发者_Go百科e @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


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.


It will have both. You can verify with the config browser plugin.


It will be able to identify both BaseAction.INDEX and BaseAction.ERROR.

If the result is available in the Subclass (In your case ReportAction class) it will follow that, Otherwise it will look in the superclass (In you case BaseAction class).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号