I would like to do something like:
But it doesn't work. Is it possible? I don't like to add interface just for creating new object.Code:<evaluate expression="new Foo()"/>
I would like to do something like:
But it doesn't work. Is it possible? I don't like to add interface just for creating new object.Code:<evaluate expression="new Foo()"/>
You have a few options for creating objects. Unfortunately, using "new" is not one of them.
You can add the object as prototype-scoped Spring bean (or a different scope, if it's always going to be limited to the same scope). In this case, there's no requirement that you have an interface for it (though that's generally a good design). If you give the bean the id of "newBeanName", in your case "newFoo", then it makes it clear that the bean is prototype scoped, and then you can set it in whichever scope you like:
Or instead, you can set your Foo object as a flow variable at the start of the flow:Code:<set name="myFoo" value="newFoo"/>
Code:<var class="my.fully.qualified.Foo" name="foo"/>
WHat if my Object constructor needs an argument which can not be autowired? Or it is derived from previous step in my Flow?
Can we do this within flow itself or we have to call Action/Service to instantiate that object?
Thanks,
Vish
This isn't valid in Web Flow 2.1 and later?:As of the Web Flow 2.1 release, Spring Expression Language (SpEL) is the default. It's possible "new" wasn't a possibility in the previous default implementation of Unified Expression Language. I'm not very familiar with with it.Code:<set name="myFoo" value="new tld.domainName.MyFoo()"/>
Last edited by MiB; Jan 23rd, 2012 at 11:26 AM.