[jboss-user] [JBoss Seam] - Re: FlushModeType not working in Seam 1.2.1 GA?

kotlusa do-not-reply at jboss.com
Sun Oct 28 14:40:30 EDT 2007


If I could attach the code I would.... but since I see no way, here's some more inline code.

I modified the booking application and deployed it on both 4.2.1GA and 4.2.2GA, both of which appear to have the same FlushMode issue.

In addition to my changes to get it working with JSF 1.2 RI I did the following:

Added the following properties to persistence.xml - to create a smpc:

  |          <property name="jboss.entity.manager.factory.jndi.name" value="java:/entityManagerFactory"/>
  |          <property name="jboss.entity.manager.jndi.name" value="java:/em"/>
  | 

Added the following to components.xml - to create a smpc:

  |     <core:managed-persistence-context name="entityManager"
  |                               auto-create="true"
  |                persistence-unit-jndi-name="java:/entityManagerFactory"/>
  | 

My new HotelBookingAction (I tried to bold the changes but that didn't work because they are in a code block):

  | //$Id: HotelBookingAction.java,v 1.49 2007/03/09 01:18:21 gavin Exp $
  | package org.jboss.seam.example.booking;
  | import static javax.persistence.PersistenceContextType.EXTENDED;
  | import java.util.Calendar;
  | import javax.ejb.Remove;
  | import javax.ejb.Stateful;
  | import javax.persistence.EntityManager;
  | import javax.persistence.PersistenceContext;
  | import org.jboss.seam.annotations.Begin;
  | import org.jboss.seam.annotations.Destroy;
  | import org.jboss.seam.annotations.End;
  | import org.jboss.seam.annotations.FlushModeType;
  | import org.jboss.seam.annotations.In;
  | import org.jboss.seam.annotations.Logger;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Out;
  | import org.jboss.seam.annotations.security.Restrict;
  | import org.jboss.seam.core.Events;
  | import org.jboss.seam.core.FacesMessages;
  | import org.jboss.seam.log.Log;
  | @Stateful
  | @Name("hotelBooking")
  | @Restrict("#{identity.loggedIn}")
  | public class HotelBookingAction implements HotelBooking
  | {
  |    
  |    @In
  |    private EntityManager entityManager;
  |    
  |    @In 
  |    private User user;
  |    
  |    @In(required=false) @Out
  |    private Hotel hotel;
  |    
  |    @In(required=false) 
  |    @Out(required=false)
  |    private Booking booking;
  |      
  |    @In
  |    private FacesMessages facesMessages;
  |       
  |    @In
  |    private Events events;
  |    
  |    @Logger 
  |    private Log log;
  |    
  |    private boolean bookingValid;
  |    
  |    @Begin(flushMode=FlushModeType.MANUAL)
  |    public void selectHotel(Hotel selectedHotel)
  |    {
  |       hotel = entityManager.merge(selectedHotel);
  |    }
  |    
  |    public void bookHotel()
  |    {      
  |       booking = new Booking(hotel, user);
  |       Calendar calendar = Calendar.getInstance();
  |       booking.setCheckinDate( calendar.getTime() );
  |       calendar.add(Calendar.DAY_OF_MONTH, 1);
  |       booking.setCheckoutDate( calendar.getTime() );
  |    }
  |    public void setBookingDetails()
  |    {
  |       Calendar calendar = Calendar.getInstance();
  |       calendar.add(Calendar.DAY_OF_MONTH, -1);
  |       if ( booking.getCheckinDate().before( calendar.getTime() ) )
  |       {
  |          facesMessages.addToControl("checkinDate", "Check in date must be a future date");
  |          bookingValid=false;
  |       }
  |       else if ( !booking.getCheckinDate().before( booking.getCheckoutDate() ) )
  |       {
  |          facesMessages.addToControl("checkoutDate", "Check out date must be later than check in date");
  |          bookingValid=false;
  |       }
  |       else
  |       {
  |          bookingValid=true;
  |       }
  |       entityManager.persist(booking);
  |    }
  |    
  |    public boolean isBookingValid()
  |    {
  |       return bookingValid;
  |    }
  |    
  |    @End
  |    public void confirm()
  |    {
  |       facesMessages.add("Thank you, #{user.name}, your confimation number for #{hotel.name} is #{booking.id}");
  |       log.info("New booking: #{booking.id} for #{user.username}");
  |       events.raiseTransactionSuccessEvent("bookingConfirmed");
  |       entityManager.flush();
  |    }
  |    
  |    @End
  |    public void cancel() {}
  |    
  |    @Destroy @Remove
  |    public void destroy() {}
  | }
  | 

This causes the booking to be persisted when you set it's details.  When you confirm the details, the entityManager is flushed.

To test this just create 1 booking and cancel on the confirmation page.  Then create another booking and confirm it.  You will see both of the bookings in your list now.

Thanks,
Austin

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4099679#4099679

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4099679



More information about the jboss-user mailing list