-
1. Re: how is DataModelSelection populated
bfo81 Jul 11, 2006 8:41 AM (in response to balamg)You have a List annotated with @DataModel (here: private List hotels). This list is being used as the <h:dataTable>'s value.
Seam is integrated into the JSF lifecycle so well, that every time a link in a table row is clicked, Seam populates the DataModelSelection property (here: private Hotel selectedHotel) with the corresponding object represented in that table row.
Well, and hotelBooking then just accesses this property of hotelSearching.
btw: I would like to know if it's really necessary to pass the hotelSearching bean to the hotelBooking bean. I would prefer passing the selected hotel directly instead of resolving it via hotelSearch.getSelectedHotel(). In my opinion the way it's done now increases coupling of the classes (HotelBooking needs Hotel AND HotelSearching) and that's a bit unaesthetic. -
2. Re: how is DataModelSelection populated
gavin.king Jul 11, 2006 12:21 PM (in response to balamg)btw: I would like to know if it's really necessary to pass the hotelSearching bean to the hotelBooking bean. I would prefer passing the selected hotel directly instead of resolving it via hotelSearch.getSelectedHotel(). In my opinion the way it's done now increases coupling of the classes (HotelBooking needs Hotel AND HotelSearching) and that's a bit unaesthetic.
Currently it is necessary, yes. @DataModelSelection fields must be balanced by @DataModel fields in a component. -
3. Re: how is DataModelSelection populated
bfo81 Jul 11, 2006 5:44 PM (in response to balamg)"gavin.king@jboss.com" wrote:
M'kay. So I'll pay that prize and stop trying to find another way ;).
Currently it is necessary, yes. @DataModelSelection fields must be balanced by @DataModel fields in a component. -
4. Re: how is DataModelSelection populated
gavin.king Jul 11, 2006 7:07 PM (in response to balamg)You *could* inject the actual ListDataModel object and call getRowSelection()...
-
5. Re: how is DataModelSelection populated
balamg Jul 12, 2006 12:57 AM (in response to balamg)there is nothing in this url
href="/seam-booking/main.seam?actionMethod=hotelBooking.selectHotel&dataModelSelection=hotels%5B3%5D"
that suggests that that the datamodelSelection property in the HotelSearchingAction needs to be set, so how does this work. ?? -
6. Re: how is DataModelSelection populated
bfo81 Jul 12, 2006 6:53 AM (in response to balamg)@Gavin:
I don't know how to get the ListDataModel object. The only thing I have is a annotated java.util.List.
@balamg:
The page main.seam is called, main.seam (or main.xhtml in reality) uses the hotelSearch managed bean, which is in reality the HotelSearchingAction instance. And this one gets the (in this case) 3rd row of the hotel list injected into the selectedHotel property. After that, the hotelBooking bean gets it's injections and the selectHotel method is invoked.
Don't know if that was 100% correct and if this was what you wanted to know. But I just had the eager to write that down ;).
@Seam team:
I write my diploma thesis in informatics about new J2EE technologies and Seam is definitely one of 'em. But there's one thing I'd like to say (and please don't be offended, just take it as constructive critisism). The examples should be the best start to get familiar with Seam and they should be templates for your own apps. But in my opinion they seem to be built in a hurry, and they're far from perfect.
Take the booking example: Open two search windows. Perform a clean search in window 1, and a search for "at" in window 2. Click on "Conrad Miami" in window 1. But instead of "Conrad Miami" you will get "Ritz Carlton" in window 1. Why? Cause the search list is a session bean, and the list of window 1 has been overwritten by the list generated by window 2's search. To get rid of this bug the search lists should have been conversational, too. Ok, it might be only a demo, but you suggest to take it as a template for an own application.
And what I really miss are simple CRUD templates. I guess there's almost no app without creating, listing, editing or deleting entities. Plus there are many "Todo"-blocks in the documentation- What is the pageflow example good for without a detailed explanation? Or mistakes like the default scope "conversation" - in fact it's "event". Then there's a blog not working, an old and small FAQ, a fragmentary problems FAQ, a deadlink to a tutorial movie, and a WIKI that just doesn't fulfill a novice's needs.
I'm sure you have diagrams showing the interaction between the classes or how Seam is exactly integrated into the JSF lifecycle. You even know many common mistakes which one should avoid. Well, we don't, and so there will always be questions like the one balamg asked.
Seam is said to be easy and it surely is... but only if you really understand how it works. If not, you definitely will run into tons of exceptions. You all have many years of J2EE expertise. But you can't premise that all programmer's out there have that knowledge, too. If you want Seam to become a killer you must also make it accessible to beginners. A good technology can't succeed without broad acceptance.
I don't want to put Seam down, no. It's great and I really want to use it. But it's very frustrating to learn it the hard way and being left alone with problems and questions. Ok, there's the forum, but we'd have to open a dozen threads every day, and that's not the way it should be ;).
Seam might be 1.0 and ready for production, but the docs and examples aren't... yet. -
7. Re: how is DataModelSelection populated
pmuir Jul 12, 2006 7:06 AM (in response to balamg)I think Gavin means
@Out private ListDataModel myList;
It will then be accessible in another bean as@In private ListDataModel myList
and the selection can be accessedmyList.getRowSelection();
assuming that myList is available as a context variable.
Documentation:
I personally think the FAQ should be a wiki page so that people can add questions and answers when they came up (e.g. Gavin and Norman gave a superb explanation on the forum of the difference between @EJB and @In that would be really useful on the FAQ). -
8. Re: how is DataModelSelection populated
bfo81 Jul 12, 2006 8:54 AM (in response to balamg)Hmm... I have the following code in my mind:
... @DataModel private List<WhatEver> whatEverList; @PersistenceContext private EntityManager em; ... @factory("whatEverList") public void populateList() { whatEverList = em.createQuery("from WhatEver").getResultList(); } ...
So how to come from that java.util.List to a ListDataModel?
Doc:
I agree with you. A growing FAQ list with the possibility of user contribution would be great. Searching the forum often is a mess since the important information is hidden between tons of posts or in threads with misleading titles. In addition to that the search function often delivers you threads that don't contain any helpful information.
Furthermore I suggest a list of "common mistakes". I mean, you often get exceptions and don't know where they come from. Or something just doesn't work the way you want to. And if you find a solution after some cups of coffee why not to record it somewhere? Another one will be grateful not to run that gauntlet again. Your entity in an editor page is null and you get a model update failure? No worries, mate, just add the forgotten @Name annotation to your entity bean and it will work (that's what I ran into today *g*).
Moreover, what about a repository of useful code pieces, templates and patterns contributed by Seam users? Never reinvent the wheel ;). Be it CRUDs or template method patterns for not repeating yourself over and over (like posted yesterday), all this can speed up your development. You're already at home with your loved ones while the Spring coders still sit in the office ;).
I don't demand perfect software for this. The Seam team has enough more important things to do. Little hacks, maybe a speziell moderated subforum, could be sufficient and very very helpful. -
9. Re: how is DataModelSelection populated
theute Jul 12, 2006 9:04 AM (in response to balamg)You can create/expand Wiki pages.
Your list of "commons mistake" already exists:
http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamProblemsFAQ
Feel free to add stuff that you think is relevant.
All you are talking about is the goal of the Wiki, please contribute. -
10. Re: how is DataModelSelection populated
pmuir Jul 12, 2006 9:54 AM (in response to balamg)http://docs.jboss.com/seam/latest/reference/en/html/annotations.html#d0e5913
http://myfaces.apache.org/api/apidocs/javax/faces/model/ListDataModel.html
This is where some familiarity with the frameworks seam glues together is good.
The wiki has an examples section (where patterns could be posted), components section (complete, working peices of code which if you include in your project can be used as seam core can be used). I'm not sure what you mean by templates... The only problem with it is that it doesn't allow for 'notify me when updated' which would be useful so that people know when a component has had a bug fix.
Writing a component/pattern can take 30 minutes, documenting it, writing an example and packaging can take 3 hours - which if you have a deadline... -
11. Re: how is DataModelSelection populated
gavin.king Jul 12, 2006 2:47 PM (in response to balamg)"bfo81" wrote:
Take the booking example: Open two search windows. Perform a clean search in window 1, and a search for "at" in window 2. Click on "Conrad Miami" in window 1. But instead of "Conrad Miami" you will get "Ritz Carlton" in window 1. Why? Cause the search list is a session bean, and the list of window 1 has been overwritten by the list generated by window 2's search. To get rid of this bug the search lists should have been conversational, too. Ok, it might be only a demo, but you suggest to take it as a template for an own application.
Well, that was the way it used to work, but I had to change it b/c so many people complained that search screens shouldn't be conversational ;-)"bfo81" wrote:
And what I really miss are simple CRUD templates.
Well, other people have asked for this, so I suppose I has better do something here...."bfo81" wrote:
Then there's a blog not working, an old and small FAQ, a fragmentary problems FAQ, a deadlink to a tutorial movie, and a WIKI that just doesn't fulfill a novice's needs.
Maintaining all this kind of stuff is VERY timeconsuming and expensive, and I have extremely limited resources. -
12. Re: how is DataModelSelection populated
gavin.king Jul 12, 2006 2:50 PM (in response to balamg)"petemuir" wrote:
I think Gavin means@Out private ListDataModel myList;
It will then be accessible in another bean as@In private ListDataModel myList
and the selection can be accessedmyList.getRowSelection();
You can even outject it as:@DataModel private List myList
and still inject@In private DataModel myList
In another bean ;-) -
13. Re: how is DataModelSelection populated
iradix Jul 12, 2006 3:01 PM (in response to balamg)When you annotate a List as a @DataModel what goes on behind the scenes is that Seam wraps that list in an object of ListDataModel and outjects it, by default into the conversation context. Since the conversation context is accessible from any other seam component there is no reason you couldn't say:
@DataModel someList
then in another bean:
@In
ListDataModel someList
or maybe even
@In(value = "someList.rowIndex")
int selectedRow
In another bean. If you injected the ListDataModel you could use the getRowIndex() method to find the selected row.
At least I think you could :) If so, actually adding a method to the seam ListDataModel to retrieve the selected object might be nice here..... -
14. Re: how is DataModelSelection populated
gavin.king Jul 12, 2006 3:06 PM (in response to balamg)"iradix" wrote:
When you annotate a List as a @DataModel what goes on behind the scenes is that Seam wraps that list in an object of ListDataModel and outjects it, by default into the conversation context.
Actually the default is: "same context as the owning component" ;-)"iradix" wrote:
@In(value = "someList.rowIndex")
int selectedRow
Actually it would need to be:"iradix" wrote:
@In("#{someList.rowIndex}")
int selectedRow;
or:"iradix" wrote:
@In("#{someList.rowData}")
Foo selectedFoo;
I also have not actually tried this, but it seems like it would probably work ;-)