This content has been marked as final.
Show 5 replies
-
1. Re: Injecting one of many objects to a variable
vata2999 Nov 9, 2011 1:41 AM (in response to kannangonka)Hi,
if i understand correctly in this case u need create instance dynamically for everyItem
instead of using @In use Component.getInstance(class, true);
public void persist100Entity(){ Item1 item1 = Component.getInstance(Item1.class, true); Item1 item2 = Component.getInstance(Item2.class, true); persist(item1); persist(item2); }
-
2. Re: Injecting one of many objects to a variable
kannangonka Nov 9, 2011 2:23 AM (in response to kannangonka)Thanks Omid. In this case, I hope that as far as the JSF page goes, I can still use {#item1.att1} etc where item1 is the @Name of the Item1 class and att1 is an attribute in that.
So, the flow goes like this:
1. From the JSF page, Seam creates an instance of Item1 at the specified context and stores the screen data
2. The session bean or entity bean can use Component.getInstance(Item1.class, true) so that seam injects the screen data into the session / entity bean for further processing.
Please confirm if my understanding is correct. -
3. Re: Injecting one of many objects to a variable
kannangonka Nov 9, 2011 2:44 AM (in response to kannangonka)Hi Omid,
One problem I will face with the approach you have mentioned is that, I need to know the correct class to instantiate. Out of the 400 items, the user might have just created 1 or 2 items. I should only instantiate those two items. Is there a way Seam can help make this job easier?
For example, can I have @Name for all these 400 items to be the same (Eg. @Name="Item") because the user anyway will work on one item at a time. Will having the same name for all items create an issue?
What are the other options we have?
Thanks.
<blockquote>
_omid pourhadi wrote on Nov 09, 2011 01:41:_<br/>
Hi,
if i understand correctly in this case u need create instance dynamically for everyItem
instead of using @In use Component.getInstance(class, true);
`public void persist100Entity(){
Item1 item1 = Component.getInstance(Item1.class, true);
Item1 item2 = Component.getInstance(Item2.class, true);
persist(item1);
persist(item2);
}`
</blockquote>
Click HELP for text formatting instructions. Then edit this text and check the preview. -
4. Re: Injecting one of many objects to a variable
chavesdaniel Nov 17, 2011 9:03 AM (in response to kannangonka)Hi,
Have you try de @Role annotation ?
-
5. Re: Injecting one of many objects to a variable
kragoth Nov 21, 2011 7:45 PM (in response to kannangonka)Seems like a rather odd scenario you have there and I'm really not sure I have any idea what you are trying to describe. But...something like this?
If the user selects that they want to create items X, Z, AA, CC you store these types (classes) in a list on a session bean.
Then your process will just loop through the list and utilize the Component.getInstance(list.get(index), true) to instantiate one of the appropriate entities.