Results 1 to 5 of 5

Thread: Can we create an object in Spring Web Flow 2 expression?

  1. #1

    Default Can we create an object in Spring Web Flow 2 expression?

    I would like to do something like:
    Code:
    <evaluate expression="new Foo()"/>
    But it doesn't work. Is it possible? I don't like to add interface just for creating new object.

  2. #2
    Join Date
    Nov 2008
    Posts
    742

    Default

    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:

    Code:
    <set name="myFoo" value="newFoo"/>
    Or instead, you can set your Foo object as a flow variable at the start of the flow:

    Code:
    <var class="my.fully.qualified.Foo" name="foo"/>

  3. #3

    Default

    Quote Originally Posted by InverseFalcon View Post
    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:

    Code:
    <set name="myFoo" value="newFoo"/>
    I think this is the best way, thanks.

    Quote Originally Posted by InverseFalcon View Post
    Or instead, you can set your Foo object as a flow variable at the start of the flow:

    Code:
    <var class="my.fully.qualified.Foo" name="foo"/>
    In some case, I want to new object after the start of the flow.

  4. #4
    Join Date
    Jan 2011
    Posts
    4

    Default

    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

  5. #5
    Join Date
    Aug 2010
    Location
    Goteborg, Sweden
    Posts
    434

    Default

    Quote Originally Posted by InverseFalcon View Post
    You have a few options for creating objects. Unfortunately, using "new" is not one of them.
    This isn't valid in Web Flow 2.1 and later?:
    Code:
    <set name="myFoo" value="new tld.domainName.MyFoo()"/>
    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.
    Last edited by MiB; Jan 23rd, 2012 at 11:26 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •