-
1. Re: save parent & child simoltaneously
vata2999 Oct 26, 2010 10:11 AM (in response to vata2999)Maybe it's better to change my question
How can I inject same context variable twice in actionBean ?@Name("relevent") @Entity class Relevent
actionBean.java
@In Relevent relevent; @In Relevent relevent2; //unknown context variable name
form.xhtml
h:inputText value{relevent.name} h:inputText value{relevent2.name} // this cause the problem
-
2. Re: save parent & child simoltaneously
kragoth Oct 28, 2010 2:09 AM (in response to vata2999)You cannot inject multiple instances of a component.
Instead of trying to inject 2 children, inject the parent and then reference the collection containing the children.
Then as long as you have a cascading relationship merging the parent will save both children. If it is not a cascading relationship then manually call persist on each child. (Assuming flush mode is manual).
-
3. Re: save parent & child simoltaneously
vata2999 Oct 28, 2010 5:39 AM (in response to vata2999)Thanks tim for your advice
You cannot inject multiple instances of a component
as i know seam-gen using java reflection to create instance of entity and bind it to a from
with entity.instance.property so i tried to make a new instance of myrelevent
class in actionbean as below@Transactional public Relevent getRelevent2(){ return Relevent.class.newInstance(); }
that works perfectly but after i bind it to a form like
h:inputText value=actionBeanName.relevent2.property
and submit form all property returns null
any other idea ? -
4. Re: save parent & child simoltaneously
lvdberg Oct 28, 2010 6:43 AM (in response to vata2999)Hi,
why don't you use the seam container to do this for you ? So something like:
<component auto-create="true" class="yourpackage.Relevent" name="relevent1" /> <component auto-create="true" class="yourpackage.Relevent" name="relevent2" />
Leo
-
5. Re: save parent & child simoltaneously
vata2999 Oct 28, 2010 7:05 AM (in response to vata2999)That was as a piece of cake! :-D you save my day
Thanks Leo -
6. Re: save parent & child simoltaneously
kragoth Oct 28, 2010 6:43 PM (in response to vata2999)
Leo van den Berg wrote on Oct 28, 2010 06:43:
Hi,
why don't you use the seam container to do this for you ? So something like:<component auto-create="true" class="yourpackage.Relevent" name="relevent1" /> <component auto-create="true" class="yourpackage.Relevent" name="relevent2" />
LeoI did not know that trick! Nice one Leo. :)