views:

43

answers:

2

Hi everyone,

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

A: 

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)

leonbloy
That was my point I would like to specify a particular parametrization for a particular mapping, and I don't know if struts2 allow that
zor
No, but you can easily code a class (sort of alias) for each parametrization you intend to use.See my other answer
leonbloy
+1  A: 

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">
leonbloy
Until struts2 allow to declare a specific type parametrization in it's configuration file, this solution is the best, and I've used it!Thanks you.zo
zor