|
|
bean as bean-action parameter
Can we pass beans from the application context as bean-action parameters?
For example, here is an application context fragment:
lt;bean id=quot;alphaquot; class=quot;...quot; /gt;
lt;bean id=quot;betaquot; class=quot;...quot; /gt;
lt;bean id=quot;beanquot; class=quot;...quot; /gt;
And here is a flow:
lt;action-state id=quot;...quot;gt; lt;bean-action bean=quot;beanquot; method=quot;doSomethingCoolquot;gt; lt;method-argumentsgt; lt;argument expression=quot; ? .alphaquot; /gt; lt;argument expression=quot; ? .betaquot; /gt; lt;/method-argumetsgt; lt;/bean-actiongt;
lt;/action-stategt;
Is it any standard way to do this?
Hi there,
If I'm understanding your problem correctly you want to use bean objects in methods of other beans and you are trying to do this by passing these bean objects via the xml flow definition.
A solution to your problem is to inject the bean objects (alpha amp; beta) into the bean object quot;beanquot;. To use your example:
lt;bean id=quot;beanquot; class=quot;...BeanClassquot;gt; lt;property=quot;alphaquot; lt;ref bean=quot;alphaBeanquot;/gt;lt;/propertygt; lt;property=quot;betaquot; lt;ref bean=quot;betaBean quot;/gt;lt;/propertygt;
lt;/beangt;
lt;bean id=quot;alphaBeanquot; class=quot;...AlphaClassquot;/gt;
lt;bean id=quot;betaBeanquot; class=quot;...BetaClassquot;/gt;
The only thing you need to do in BeanClass to use alpha and beta is to create getters and setters in this class.
public class BeanClass
{ private Alpha alpha; private Beta beta;
Alpha getAlpha() { return alpha; }
void setAlpha(Alpha alpha) { this.alpha = alpha; }
Beta getBeta { return beta; }
void setBeta(Beta beta) { this.beta = beta; }
public void doSomethingCool( ) { alpha.methodYouNeed beta.methodYouNeed }
}
I hope this helps you to solve your problem
Raoul
to Mister_Lie:
yes, your have understood the problem. But your method is not a solution. I need really dynamic invocation and I do not want to place into main application context some dependencies on a concrete flow. Example:
lt;bean-action bean=quot;beanquot; method=quot;doSomethingCoolquot;gt;
lt;method-argumentsgt;
lt;argument expression=quot; ? .alphaquot; /gt;
lt;argument expression=quot;flowScope.formquot; /gt;
lt;/method-argumetsgt;
lt;/bean-actiongt;
At this moment I am using additional quot;publisherquot; and I am thinking such functionality can be needed by some other people.
Can you explain the dynamic invocation you need to me?
I understand that you don't want to place dependencies of a concrete flow into your main application context, but you can create an application context especially for the concrete flow and import it in the flow.
Example:
lt;bean-action bean=quot;beanquot; method=quot;doSomethingCoolquot;gt; lt;method-argumentsgt; lt;argument expression=quot; ? .alphaquot; /gt; lt;argument expression=quot;flowScope.formquot; /gt; lt;/method-argumetsgt;
lt;/bean-actiongt;
lt;import resource=quot;flow-beans.xmlquot;/gt;
Raoul
Yes, and really I want to pass this imported beans as parameters to methods of beans from the global application context. In this example bean with id quot;beanquot; is some application scope object, e.g. some DAO. Then bean quot;alphaquot; is some bean from imported context quot;flow-beans.xmlquot;.
Of course, I can use proposed aproach (and I already have been using it). But from other point of view there are many scopes in flow, and why we are not using one more quot;contextquot; scope? |
|