Announcement Announcement Module
Collapse
No announcement yet.
Can we create an object in Spring Web Flow 2 expression? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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"/>

    Comment


    • #3
      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.

      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.

      Comment


      • #4
        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

        Comment


        • #5
          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, 11:26 AM.

          Comment

          Working...
          X