-
1. Re: Multiple roles and accessing the DataModel
zzzz8 Sep 14, 2006 1:55 AM (in response to zzzz8)I hate to move this thread up (and it's probably bad etiquette), but I would really appreciate some help here. I'm really at a lost here and I certainly don't want to explicitly wrap the List object in a DataModel object... I don't think it should take too long to respond either - please tell me if I'm doing something stupid... :) Please help! Thanks!
-
2. Re: Multiple roles and accessing the DataModel
raja05 Sep 14, 2006 3:19 AM (in response to zzzz8)"zzzz8" wrote:
However, when I do this, I don't seem to be getting the DataModel, but rather the actual List itself. This is evidenced by the fact that a method in the class that uses the DataModelSelection is always stuck at pointing to the first item in the List list...
Can you elaborate on that bit, especially the "first item in the List". The way it is, your List will get wrapped into a ListDataModel before its sent out to the view and unwrapped on its way back. -
3. Re: Multiple roles and accessing the DataModel
denis-karpov Sep 14, 2006 3:35 AM (in response to zzzz8)You should use it like this #{list}, because when you use @DataModel Seam outjected wrapper into the current context with name of the property (list in your case)
Another way you should wrap it by yourself, only then you can use it the way #{YourBean.YourModel} -
4. Re: Multiple roles and accessing the DataModel
gavin.king Sep 14, 2006 4:52 AM (in response to zzzz8)"denis-karpov" wrote:
You should use it like this #{list}, because when you use @DataModel Seam outjected wrapper into the current context with name of the property (list in your case)
Right. -
5. Re: Multiple roles and accessing the DataModel
zzzz8 Sep 14, 2006 12:28 PM (in response to zzzz8)It would be nice to change the Seam spec such that one can apply the DataModel annotation to the getter method of the list so that one can use the DataModel in multiple roles without explicitly wrapping the list (in the source code) in a DataModel object. I guess I'm suggesting this because I'm quite sure I will run into this problem in the future (and I just hate explicitly wrapping the list in a DataModel).
Again, thanks for all the help. -
6. Re: Multiple roles and accessing the DataModel
gavin.king Sep 14, 2006 12:39 PM (in response to zzzz8)You can use @DataModel on a getter method.
-
7. Re: Multiple roles and accessing the DataModel
zzzz8 Sep 14, 2006 2:15 PM (in response to zzzz8)"gavin.king@jboss.com" wrote:
You can use @DataModel on a getter method.
Hi Gavin,
I understand you can use the DataModel annotation on the getter method, but if you have two instances of this component "alive" at the same time, with one component associated with the default component name and the other with another role, then it would not work - because the outjected context DataModel context variable cannot be associated with two roles at the same time - i.e. the client cannot distinguish if the list DataModel context variable belongs to the component1 role or the component2 role. This is the limitation I was referring to and something I hope can be dealt with in the future. -
8. Re: Multiple roles and accessing the DataModel
eekboom Sep 14, 2006 6:49 PM (in response to zzzz8)I think the only way to do this is to create a getter that returns the already wrapped field and then use the "parent" components name , something like
public DataModel getListModel() { return new ListDataModel(list);
then #{component1.listModel} and #{component2.listModel} should return the appropriate models.
And yes, there's a bug with selection and index in the same class:
http://jira.jboss.org/jira/browse/JBSEAM-270 -
9. Re: Multiple roles and accessing the DataModel
denis-karpov Sep 15, 2006 3:44 AM (in response to zzzz8)In this case you can use:
yourBean.getYourModel.getRowData(); yourBean.getYourModel.getRowIndex();
But you should not create DataModel each time in a getter.
I use it something like this:private DataModel dm = null; public DataModel getDetails() { if (dm==null){ dm = new ListDataModel(); } return dm; } private void syncDetails() { Client o = getObject(); if (o!=null){ getDetails().setWrappedData(o.getDocuments()); } } private IdentityCard getSelectedDocument() { return (IdentityCard)getDetails().getRowData(); }
Frankly, I do not like
@DataModel
@DataModelSelection
@DataModelSelectionIndex