Hi Mark;
Your XML definition is not correct, I think. Specification says that, the
immediate children of the XML bean declaration which correspond to *Java Type*
is captured as a *parameters* of this constructor. So the correct XML
definition may be written as;
<myapp:TstBeanConstructor>
<RequestScoped/>
<lang: Integer/>
</myapp:TstBeanConstructor>
where *lang* is the namespace that corresponds to the *java.lang* package. You
are able to give any namespace instead of *lang*.
When the container creates this bean instance, it will inject the constructor
parameter with looking the beans with API type *Integer* and Binding Type
*...@current*. If it finds the bean successfully, it injects its current
instance.
For example, lets say that we define producer method in other bean class
(MyOtherBean) .
class MyOtherBean
{
@RequestScoped @Produces
public int getTstBeanConstructorInitialValue()
{
return 12;
}
}
Then, container calls this method via its parent bean instance (MyOtherBean)
and injects the resulted instance (Integer:12) into the TstBeanConstructor.
I did not try to execute this sample, but I think it works.
Please look at the specification that contains full explanation of the XML
defined constructor declaration.
/Gurkan
________________________________
From: Mark Struberg <[email protected]>
To: [email protected]
Sent: Tuesday, January 13, 2009 10:51:43 PM
Subject: XML definition for constructor injection
grr, my first mail got eaten by the spam daemon
--- Mark Struberg <[email protected]> schrieb am Di, 13.1.2009:
> Von: Mark Struberg <[email protected]>
> Betreff:
> An: [email protected]
> Datum: Dienstag, 13. Januar 2009, 21:46
> Hi!
>
> I like to test the constructor injection via XML
> definition.
>
> For what I understand after reading the spec, the following
> should work:
>
> Assume we have the WebBean, _without_ any annotations:
>
> public class TstBeanConstructor
> {
>
> private int i1=0;
> private int i2=0;
>
> public TstBeanConstructor(int i1)
> {
> this.i1 = i1*100;
> }
>
> public int getI1()
> ...
>
>
> and the XML looks like:
>
> <myapp:TstBeanConstructor>
> <RequestScoped/>
> <myapp:TstBeanConstructor>
> <myapp:i1>12</myapp:i1>
>
> </myapp:TstBeanConstructor>
> </myapp:TstBeanConstructor>
>
>
> should this work? At first I was a bit confused about the 2
> <myapp:TstBeanConstructor>, is this correct in the
> XML?
>
> txs and LieGrue,
> strub