OK, I tried the above. Specifically, I wanted to make it so the hotel/booking
noejb example brings up the hotel list the first time you land on main.xhtml,
without starting a conversation. The hotel list is in session scope, in other
words, just like the booking list. Then the "View Hotel" links become plain
links with "hotelId" request parameters, for bookmarkability.
So I split HotelBookingAction into HotelListAction (SESSION scope, responsible
for the "hotels" datamodel) and HotelBookingAction (the editing methods, still
conversational). HotelListAction's find() method becomes a @Factory("hotels")
method. There is a new HotelFactory class, which creates the "hotel" component
from the "View Hotels" link. So the "View Hotel" links actually read
http://localhost:8080/tomcat-seam-noejb/hotel.jsf?hotelId=9 which is fine.
(HotelFactory was originally @Stateless but it started complaining about no
@JndiName, which I didn't want to have to mess with, so I just made it
@Scope(STATELESS).)
All of this works... EXCEPT for the interaction between the HotelFactory and
the HotelListAction. Basically, I want the "Next Hotel" and "Previous Hotel"
buttons in hotel.xhtml to work, regardless of whether I arrived at hotel.xhtml
from main.xhtml or from a bookmarked link. Somehow I need the HotelFactory
(the only bean that gets invoked when a bookmarked hotel.jsf link is loaded) to
be aware of "hotels" and "hotelIndex", so it can set "hotelIndex"
appropriately. Otherwise HotelListAction.nextHotel and
HotelListAction.previousHotel don't work properly.
Here's my stab at HotelFactory.
/**
| * Factory class to create a single hotel based on request parameter.
| */
| @Name("hotelFactory")
| @Scope(ScopeType.STATELESS)
| public class HotelFactory {
| private static final Logger log = Logger.getLogger(HotelFactory.class);
|
| @Out Hotel hotel;
| @RequestParameter String hotelId;
|
| @In(create=true)
| private Session bookingDatabase;
|
| @In
| private List<Hotel> hotels; // big trouble with the type of this field
| @Out
| private int hotelIndex;
|
| @Factory("hotel")
| public void getHotel() {
| long hotelId = Long.parseLong(this.hotelId);
|
| hotel = (Hotel)bookingDatabase.createQuery("from Hotel where id = ?")
| .setParameter(0, hotelId)
| .uniqueResult();
|
| if (hotels != null) {
| for (int i = 0; i < hotels.size(); i++) {
| Hotel listHotel = (Hotel) hotels.get(i);
| // have to compare id's because "hotel" and "hotels" were
loaded in different
| // persistence sessions (since there's no common context for
them both).
| if (hotel.getId().equals(listHotel.getId())) {
| hotelIndex = i;
| break;
| }
| }
| }
|
| log.info("got hotel for id " + hotelId + ": " + hotel);
| }
| }
As you can see from the comments, this doesn't work. It actually fails to
biject "hotels".
- If I declare "hotels" as "@In private List hotels", it fails, because it
tries to inject a ListDataModel value into HotelFactory.hotels, which (sensibly
enough) gives an IllegalArgumentException at
sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63).
- If I declare "hotels" as "@In @DataModel private List hotels", it fails for
the same reason -- still trying to inject a ListDataModel into a List.
- If I start flailing wildly and declare "hotels" as "@In @DataModel private
ListDataModel hotels", munging the code around to call .getWrappedData() etc.,
etc., then it actually injects successfully and updates hotelIndex properly.
THEN it dies with:
java.lang.ClassCastException: org.jboss.seam.jsf.ListDataModel
| at org.jboss.seam.Component.outjectDataModel(Component.java:773)
| at org.jboss.seam.Component.outject(Component.java:695)
Line 773 is:
list = (List) getFieldValue( bean, dataModelGetter, name );
Seems like Seam's got me coming and going on this one! :-) Either it won't
inject a List, or it won't outject a ListDataModel!
What gives? The above seems crufty even to me (even if it worked it would be
crufty), so I'm wondering whether there's just a better way to do all this. Is
there an existing sample showing how to use a session-scoped list, RESTful item
links, and next/previous item navigation all together? How's that blog sample
coming? ;-)
Also, as you can see, I have to compare IDs rather than just using
"hotels.indexOf(hotel)" since there doesn't seem to be a shared persistence
context. (In other words, Hibernate session caching not working in this case.)
Is that expected?
I'm also using a CVS snapshot from late January, not Beta2. Would any of this
be different in Beta2?
Thanks again. Worst comes to worst, I'll bail on trying to keep the
session-scoped list in sync.
Cheers,
Rob
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3923205#3923205
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3923205
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user