What's the cleanest way to handle this situation?
I've got nested business objects that implement interfaces so the client is
never privy to the concrete classes. Of course when I try to use Stripes
default instantiation, it complains (see message below) because it sees the
interface and doesn't know what type of concrete class to implement.
>From ReflectUtil.getInterfaceInstance()
"Stripes needed to instantiate a property who's declared type as an " +
"interface (which obviously cannot be instantiated. The
interface is not " +
"one that Stripes is aware of, so no implementing class
was known. The " +
"interface type was: '" + interfaceType.getName() + "'.
To fix this " +
"you'll need to do one of three things. 1) Change the
getter/setter methods " +
"to use a concrete type so that Stripes can instantiate
it. 2) in the bean's " +
"setContext() method pre-instantiate the property so
Stripes doesn't have to. " +
"3) Bug the Stripes author ;) If the interface is a JDK
type it can easily be " +
"fixed. If not, if enough people ask, a generic way to
handle the problem " +
"might get implemented.");
It would be great if there were a way to specify a mapping for an interface
to an instantiator so that I could define a method to handle the
instantiation.
Is there a way to do that? I got the impression from the message above that
there was not.
Barring that, I could try to pre-instantiate the concrete class as suggested
in the message above, but I'm not sure the best way to do that. Should I
set up a @Before binding with a handler that iterates through all the
request parameters and pre-instantiates based on those? That seems a little
clunky.
So basically, this is my situation:
In the .jsp:
<s:text name="snapshot.goals.dietGoals[${loop.index}].text" />
snapshot.getGoals().getDietGoals() returns a List<Goal>. Goal is an
interface. snapshot.getGoals() returns a Goals interface which has a
method, Goal getDietGoal(String text), which returns an instance of a Goal.
I really just want to tell Stripes to use goals.getDietGoal(text) to
instantiate my type.
Is there a good way to do that?
Thanks,
Peter
--
View this message in context:
http://www.nabble.com/preinstantiate-interface-type-tp22152219p22152219.html
Sent from the stripes-users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users