How to declare a Generics Action in struts2.xml file?

南楼画角 提交于 2019-12-13 03:03:56

问题


My problems is in a Struts2 action, where

I have a class :

public class MyAction<T> extends ActionSupport

with a private member like this :

private T myData;

And I would like to declare this aciton in the struts.xml file, how can i manage to do so ?

Thanks for the answer.

Ps : I've tried without declaration of T, but it did not work


回答1:


For example, you cannot obvioulsy write (in struts-XX.xml)

<action name="doSomething" class="xx.xx.MyAction<java.util.Date>">

But you can easily code a class (sort of alias) for each parametrization you intend to use.

public class MyAction_Date extends MyAction<java.util.Date> {}

and then :

<action name="doSomething" class="xx.xx.MyAction_Date">



回答2:


In struts2 the action object is instantiated by the framework for each request. Then, I don't think you can use a parametrized class for that. (Except if struts allows you to specify a particular class parametrization, say MyAction<Date> , for a particular action mapping - I don't think it allows that)



来源:https://stackoverflow.com/questions/2516407/how-to-declare-a-generics-action-in-struts2-xml-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!