5 Replies Latest reply on Feb 2, 2009 4:17 PM by Tony Herstell

    reattaching entities to stop detached entity exception

    Tony Herstell Master

      Using PickingList (on a Seam project) I found that I had to re-attach all the objects that were used in the component (see code later). I hope that is what you expected to happen.

      I did also have to convert the EntityManager to a Seam managed one to get convertEntity to work.


      <!-- ***********
       Sponsors
       *********** -->
       <s:decorate id="entity_event_sponsors_decorator" template="../edit.xhtml">
       <ui:define name="label">
       <h:outputText value="#{messages.entity_event_sponsors_label}" />
       </ui:define>
       <ui:define name="content">
       <div>
       <rich:pickList value="#{event.sponsors}" sourceListWidth="300px" targetListWidth="300px">
       <s:selectItems value="#{availableUsers}" var="eachUser" label="#{eachUser.surname} , #{eachUser.firstname}"/>
       <s:convertEntity/>
       </rich:pickList>
       </div>
       </ui:define>
       <ui:define name="hint">
       <s:formattedText value="#{messages.entity_event_sponsors_hint}" />
       </ui:define>
       </s:decorate>
      


      this.classEntity.setSponsors(reattachUsers(this.classEntity.getSponsors()));
      
      ...
      this.allEventsClasses.add(this.classEntity);
      entityManager.persist(this.event);
      
      




        • 1. Re: reattaching entities to stop detached entity exception
          Nick Belaevski Master

          Hi,

          Seems not like the way I would like to see things done. Maybe ask at Seam forum or post full beans code and let us check?

          • 2. Re: reattaching entities to stop detached entity exception
            Tony Herstell Master

            findEvents(); calls findUsers(); as Seam only seems to run 1 factory.

            enter() is where you always enter this method (obvious really as it has @Begin on it)


            Notice the "Reattach Users" routine... this is just to deal with the detached users that come back from the RF component.

            I do see a lot of exceptions being caught in the server log using that component... conversation problems...

            Good luck...



            
            package nz.co.selwynequestriancentre.model.entity.event;
            
            public enum ClassEntityKind {
             DRESSAGE ("class_dressage"),
             SJ ("class_sj"),
             COMBINED ("class_combined"),
             SHOWING ("class_showing");
             private final String inlLabel;
             ClassEntityKind(String inlLabel) {
             this.inlLabel = inlLabel;
             }
             public String getInlLabel() { return inlLabel; }
            }
            
            
            
            
            
            
            package nz.co.selwynequestriancentre.action.events;
            
            import java.io.IOException;
            import java.io.Serializable;
            import java.util.ArrayList;
            import java.util.GregorianCalendar;
            import java.util.List;
            
            import javax.ejb.Remove;
            import javax.ejb.Stateful;
            import javax.ejb.TransactionAttribute;
            import javax.ejb.TransactionAttributeType;
            import javax.faces.model.SelectItem;
            import javax.persistence.EntityManager;
            import javax.persistence.PersistenceContext;
            import javax.persistence.PersistenceContextType;
            
            import nz.co.selwynequestriancentre.model.entity.Image;
            import nz.co.selwynequestriancentre.model.entity.Images;
            import nz.co.selwynequestriancentre.model.entity.MaintenanceDates;
            import nz.co.selwynequestriancentre.model.entity.User;
            import nz.co.selwynequestriancentre.model.entity.event.ClassEntity;
            import nz.co.selwynequestriancentre.model.entity.event.ClassEntityKind;
            import nz.co.selwynequestriancentre.model.entity.event.ClassEntityStatusKind;
            import nz.co.selwynequestriancentre.model.entity.event.Event;
            import nz.co.selwynequestriancentre.model.entity.event.EventWorkflowStateKind;
            
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.Begin;
            import org.jboss.seam.annotations.Conversational;
            import org.jboss.seam.annotations.Destroy;
            import org.jboss.seam.annotations.End;
            import org.jboss.seam.annotations.Factory;
            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.Scope;
            import org.jboss.seam.annotations.datamodel.DataModel;
            import org.jboss.seam.international.StatusMessages;
            import org.jboss.seam.international.StatusMessage.Severity;
            import org.jboss.seam.log.Log;
            import org.richfaces.event.UploadEvent;
            import org.richfaces.model.UploadItem;
            
            /**
             * @author Tony Herstell
             * @version $Revision: 1.14 $ $Date: 2009-01-30 05:17:42 $
             */
            @SuppressWarnings("serial")
            @Stateful
            @Conversational
            @Scope(value=ScopeType.CONVERSATION)
            @Name("eventsController")
            public class EventsControllerImpl implements EventsController, Serializable {
            
             /**
             * Inject and leverage the Seam Logger.
             */
             @Logger
             private Log log;
            
             /**
             * Inject the EJB3 Persistence context.
             */
             @PersistenceContext(type=PersistenceContextType.EXTENDED)
             private EntityManager entityManager;
            
             /**
             * Inject the Faces Messages component so that messages (errors and info)
             * can be sent to the View
             */
             @In(create = true)
             private transient StatusMessages statusMessages;
            
             @DataModel(value="availableEvents")
             private List<Event> eventList;
            
             @DataModel(value="allEventsClasses")
             private List<ClassEntity> allEventsClasses;
            
             @DataModel(value="eventsPrizePics")
             private List<Image> eventsPrizePics;
            
             @DataModel(value="eventsWinnerPics")
             private List<Image> eventsWinnerPics;
            
             @DataModel(value="classEntityPrizePics")
             private List<Image> classEntityPrizePics;
            
             @DataModel(value="classEntityWinnerPics")
             private List<Image> classEntityWinnerPics;
            
             /**
             * Outject the maximum number of uploadsAvailabe for Prize pictures.
             */
             @Out
             int eventPrizePicsMaxUploadsAvailable = 10;
            
             /**
             * Outject the number of uploadsAvailabe for Prize pictures.
             */
             @Out
             int eventPrizePicsUploadsAvailable = 10;
            
             /**
             * Outject the maximum number of uploadsAvailabe for Winner pictures.
             */
             @Out
             int eventWinnerPicsMaxUploadsAvailable = 10;
            
             /**
             * Outject the number of uploadsAvailabe for Winner pictures.
             */
             @Out
             int eventWinnerPicsUploadsAvailable = 10;
            
             /**
             * Outject the maximum number of uploadsAvailabe for Prize pictures.
             */
             @Out
             int classEntityPrizePicsMaxUploadsAvailable = 10;
            
             /**
             * Outject the number of uploadsAvailabe for Prize pictures.
             */
             @Out
             int classEntityPrizePicsUploadsAvailable = 10;
            
             /**
             * Outject the maximum number of uploadsAvailabe for Winner pictures.
             */
             @Out
             int classEntityWinnerPicsMaxUploadsAvailable = 10;
            
             /**
             * Outject the number of uploadsAvailabe for Winner pictures.
             */
             @Out
             int classEntityWinnerPicsUploadsAvailable = 10;
            
             @In(required=false) @Out(required=false)
             private Event event = null;
            
             @In(required=false) @Out(required=false)
             private ClassEntity classEntity = null;
            
             /**
             * Outject a mode of operation for Events so that the pages can act on it.
             */
             @Out
             private Mode mode;
            
             /**
             * Outject a mode of operation for Classes so that the pages can act on it.
             */
             @Out(required=false)
             private Mode classEntityMode;
            
            
             @Out
             private static final ClassEntityKind[] classEntityKinds = ClassEntityKind.values();
            
             @Out(value="availableUsers",required=true)
             private List<User> availableUsers = new ArrayList<User>();
            
             private static final String CONFIGS_PACKAGE = "/pages/events/createUpdateEvent/";
             private List<SelectItem> configurations = new ArrayList<SelectItem>();
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#findEvents()
             */
             @Factory("availableEvents")
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             @Override
             public void findEvents()
             {
             if (eventList == null) {
             eventList = (List<Event>)entityManager.createQuery("from Event e order by e.entriesCloseDate asc").getResultList();
             }
             findUsers();
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#findUsers()
             */
             @Factory("availableUsers")
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             @Override
             public void findUsers()
             {
             if (availableUsers.isEmpty()) {
             availableUsers = (List<User>)entityManager.createQuery("from User u order by u.surname asc").getResultList();
             }
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#enter()
             */
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             @Override
             @Begin
             public String enter() {
             log.info(">enter");
             this.event = null;
             this.mode = Mode.READ;
             // Used for editor component.
             configurations.add(new SelectItem(CONFIGS_PACKAGE + "simple", "Simple"));
             configurations.add(new SelectItem(CONFIGS_PACKAGE + "advanced", "Advanced"));
             log.info("<enter");
             return "eventSelection";
             }
            
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#viewEvent(nz.co.selwynequestriancentre.model.entity.event.Event)
             */
             @Override
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public String viewEvent(Event event) {
             this.event = event;
             this.eventsPrizePics = this.event.getPrizes().getActualImages();
             this.eventsWinnerPics = this.event.getWinners().getActualImages();
             this.allEventsClasses = event.getClasses();
             this.mode = Mode.READ;
             return "viewEvent";
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#updateEvent(nz.co.selwynequestriancentre.model.entity.event.Event)
             */
             @Override
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public String updateEvent(Event event) {
             this.event = event;
             this.mode = Mode.UPDATE;
             eventPrizePicsUploadsAvailable = 10;
             if (event.getPrizes() != null && event.getPrizes().getActualImages() != null) {
             this.eventsPrizePics = event.getPrizes().getActualImages();
             eventPrizePicsUploadsAvailable = 10 - this.eventsPrizePics.size();
             }
             eventWinnerPicsUploadsAvailable = 10;
             if (event.getWinners() != null && event.getWinners().getActualImages() != null) {
             this.eventsWinnerPics = event.getWinners().getActualImages();
             eventWinnerPicsUploadsAvailable = 10 - this.eventsWinnerPics.size();
             }
             return "createUpdateEvent";
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#createEvent()
             */
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             @Override
             public String createEvent() {
             log.info(">createEvent");
             this.event = new Event();
             Images prizeImages = new Images();
             prizeImages.setActualImages(new ArrayList<Image>());
             this.event.setPrizes(prizeImages);
             this.eventsPrizePics = prizeImages.getActualImages();
             Images winnerImages = new Images();
             winnerImages.setActualImages(new ArrayList<Image>());
             this.event.setWinners(winnerImages);
             this.eventsWinnerPics = winnerImages.getActualImages();
             this.mode = Mode.CREATE;
             this.event.setEventWorkflowStateKind(EventWorkflowStateKind.SETUP);
             eventPrizePicsUploadsAvailable = 10;
             eventWinnerPicsUploadsAvailable = 10;
             log.info("<createEvent");
             return "createUpdateEvent";
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#saveEvent()
             */
             @TransactionAttribute(TransactionAttributeType.REQUIRED)
             @Override
             public String saveEvent() {
             log.info(">saveEvent Mode=[" + this.mode.toString() + "]");
             this.event.setSponsors(reattachUsers(this.event.getSponsors()));
             this.event.setCatering(reattachUsers(this.event.getCatering()));
             this.event.setGroundJurors(reattachUsers(this.event.getGroundJurors()));
             this.event.setHelpers(reattachUsers(this.event.getHelpers()));
             this.event.setJudges(reattachUsers(this.event.getJudges()));
             this.event.setOrganisers(reattachUsers(this.event.getOrganisers()));
             this.event.setPress(reattachUsers(this.event.getPress()));
             this.event.setRulesOfficers(reattachUsers(this.event.getRulesOfficers()));
             this.event.setScorers(reattachUsers(this.event.getScorers()));
             this.event.setSecretaries(reattachUsers(this.event.getSecretaries()));
             this.event.setTechnicalDelegates(reattachUsers(this.event.getTechnicalDelegates()));
             if (this.mode == Mode.CREATE) {
             GregorianCalendar now = new GregorianCalendar();
             MaintenanceDates maintenanceDates = new MaintenanceDates();
             maintenanceDates.setCreationDate(now.getTime());
             maintenanceDates.setDateEffectiveFrom(now.getTime());
             this.event.setDates(maintenanceDates);
             entityManager.persist(this.event);
             statusMessages.addFromResourceBundle(Severity.INFO, "entity_event_created_successfully");
             this.eventList.add(this.event);
             } else if (mode == Mode.UPDATE) {
             entityManager.persist(this.event);
             statusMessages.addFromResourceBundle(Severity.INFO, "entity_event_updated_successfully");
             }
             this.event=null;
             this.mode=Mode.READ;
             log.info("<saveEvent");
             return "success";
             }
            
             /**
             * @param userList the list of Users to be reattached
             * @return reattaches the user list elements to the EntityManager
             */
             private List<User> reattachUsers(List<User> userList) {
             List<User> reattchedUsers = new ArrayList<User>();
             for (User eachUser : userList) {
             reattchedUsers.add(entityManager.merge(eachUser));
             }
             return reattchedUsers;
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#deleteEvent(nz.co.selwynequestriancentre.model.entity.event.Event)
             */
             @TransactionAttribute(TransactionAttributeType.REQUIRED)
             @Override
             public void deleteEvent(Event event) {
             entityManager.remove(event);
             eventList.remove(event);
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#previewText()
             */
             @Override
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public void previewText() {
             log.info(">Preview Text");
             log.info("<Preview Text");
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#createClassEntity()
             */
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public String createClassEntity() {
             log.info(">createClassEntity");
             this.classEntity = new ClassEntity();
             Images prizeImages = new Images();
             prizeImages.setActualImages(new ArrayList<Image>());
             this.classEntity.setPrizes(prizeImages);
             this.classEntityPrizePics = prizeImages.getActualImages();
             Images winnerImages = new Images();
             winnerImages.setActualImages(new ArrayList<Image>());
             this.classEntity.setWinners(winnerImages);
             this.classEntityWinnerPics = winnerImages.getActualImages();
             this.classEntityMode = Mode.CREATE;
             this.classEntity.setClassEntityStatusKind(ClassEntityStatusKind.ON);
             classEntityPrizePicsUploadsAvailable = 10;
             classEntityWinnerPicsUploadsAvailable = 10;
             log.info("<createClassEntity");
             return "createUpdateClassEntity";
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#updateClassEntity(nz.co.selwynequestriancentre.model.entity.event.ClassEntity)
             */
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public String updateClassEntity(ClassEntity eventClassEntity) {
             classEntityMode = Mode.UPDATE;
             this.classEntity = eventClassEntity;
             classEntityPrizePicsUploadsAvailable = 10;
             if (classEntity.getPrizes() != null && classEntity.getPrizes().getActualImages() != null) {
             this.classEntityPrizePics = classEntity.getPrizes().getActualImages();
             classEntityPrizePicsUploadsAvailable = 10 - this.classEntityPrizePics.size();
             }
             classEntityWinnerPicsUploadsAvailable = 10;
             if (classEntity.getWinners() != null && classEntity.getWinners().getActualImages() != null) {
             this.classEntityWinnerPics = classEntity.getWinners().getActualImages();
             classEntityWinnerPicsUploadsAvailable = 10 - this.classEntityWinnerPics.size();
             }
             return "createUpdateClassEntity";
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#viewClassEntity(nz.co.selwynequestriancentre.model.entity.event.ClassEntity)
             */
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public String viewClassEntity(ClassEntity eventClassEntity) {
             this.classEntityMode = Mode.READ;
             this.classEntity = eventClassEntity;
             this.classEntityPrizePics = this.classEntity.getPrizes().getActualImages();
             this.classEntityWinnerPics = this.classEntity.getWinners().getActualImages();
             return "viewClassEntity";
             }
            
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.events.EventsController#saveClass()
             */
             @TransactionAttribute(TransactionAttributeType.REQUIRED)
             @Override
             public String saveClass() {
             log.info(">saveClass Mode=[" + this.classEntityMode.toString() + "]");
             this.classEntity.setSponsors(reattachUsers(this.classEntity.getSponsors()));
             if (this.classEntityMode == Mode.CREATE) {
             GregorianCalendar now = new GregorianCalendar();
             MaintenanceDates maintenanceDates = new MaintenanceDates();
             maintenanceDates.setCreationDate(now.getTime());
             maintenanceDates.setDateEffectiveFrom(now.getTime());
             this.classEntity.setDates(maintenanceDates);
             if (this.allEventsClasses == null) {
             this.allEventsClasses = new ArrayList<ClassEntity>();
             this.event.setClasses(this.allEventsClasses);
             }
             this.allEventsClasses.add(this.classEntity);
             entityManager.persist(this.event);
             statusMessages.addFromResourceBundle(Severity.INFO, "entity_class_created_successfully");
             } else if (this.classEntityMode == Mode.UPDATE) {
             entityManager.persist(this.event);
             statusMessages.addFromResourceBundle(Severity.INFO, "entity_class_updated_successfully");
             }
             this.classEntity=null;
             this.classEntityMode=Mode.READ;
             log.info("<saveClass");
             return "success";
             }
            
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#deleteClassEntity(nz.co.selwynequestriancentre.model.entity.event.ClassEntity)
             */
             @TransactionAttribute(TransactionAttributeType.REQUIRED)
             @Override
             public void deleteClassEntity(ClassEntity classEntity) {
             entityManager.remove(classEntity);
             allEventsClasses.remove(classEntity);
             }
            
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#backToEntityList()
             */
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             @Override
             public String backToEntityList() {
             log.info(">back");
             this.event = null;
             this.eventsPrizePics = null;
             this.mode = Mode.READ;
             log.info("<back");
             return "eventSelection";
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#backToEntityList()
             */
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             @Override
             public String backToEntityView() {
             log.info(">back");
             this.mode = Mode.READ;
             log.info("<back");
             return "viewEvent";
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.events.EventsController#listenerForPrizesPictureUploads(org.richfaces.event.UploadEvent)
             */
             @Override
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public void listenerForEventPrizesPictureUploads(UploadEvent event) throws IOException {
             List<UploadItem> uploadedImages = event.getUploadItems();
             for (UploadItem eachItem : uploadedImages) {
             Image theImage = new Image();
             theImage.setImage(eachItem.getData());
             theImage.setName(eachItem.getFileName());
             String mime = guessMime(eachItem);
             if (mime != null) {
             theImage.setType(mime); // eachItem.getContentType() <- Always octet type
             }
             if (this.event.getPrizes() == null) {
             Images images = new Images();
             images.setActualImages(new ArrayList<Image>());
             this.event.setPrizes(images);
             }
             Images prizes = this.event.getPrizes();
             List<Image> actualImages = prizes.getActualImages();
             actualImages.add(theImage);
             eventPrizePicsUploadsAvailable = 10 - this.eventsPrizePics.size();
             }
             }
            
            
            
             /**
             * @param eachItem is the Item uploaded
             * @return the guessed mime type
             */
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             private String guessMime(UploadItem eachItem) {
             String mime = null;
             int extDot = eachItem.getFileName().lastIndexOf('.');
             if(extDot > 0){
             String extension = eachItem.getFileName().substring(extDot +1);
             if("bmp".equals(extension)){
             mime="image/bmp";
             } else if("jpg".equals(extension) || "jpeg".equals(extension)){
             mime="image/jpeg";
             } else if("gif".equals(extension)){
             mime="image/gif";
             } else if("png".equals(extension)){
             mime="image/png";
             } else {
             mime = "image/unknown";
             }
             }
             return mime;
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.events.EventsController#deletePrizePicture(nz.co.selwynequestriancentre.model.entity.Image)
             */
             @Override
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public void deleteEventPrizePicture(Image image) {
             Images prizes = this.event.getPrizes();
             List<Image> actualImages = prizes.getActualImages();
             actualImages.remove(image);
             // Orphaned Image
             entityManager.remove(image);
             this.eventsPrizePics = this.event.getPrizes().getActualImages();
             eventPrizePicsUploadsAvailable = 10 - this.eventsPrizePics.size();
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.events.EventsController#listenerForWinnersPictureUploads(org.richfaces.event.UploadEvent)
             */
             @Override
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public void listenerForEventWinnersPictureUploads(UploadEvent event) throws IOException {
             List<UploadItem> uploadedImages = event.getUploadItems();
             for (UploadItem eachItem : uploadedImages) {
             Image theImage = new Image();
             theImage.setImage(eachItem.getData());
             theImage.setName(eachItem.getFileName());
             String mime = guessMime(eachItem);
             if (mime != null) {
             theImage.setType(mime); // eachItem.getContentType() <- Always octet type
             }
             if (this.event.getWinners() == null) {
             Images images = new Images();
             images.setActualImages(new ArrayList<Image>());
             this.event.setWinners(images);
             }
             Images winners = this.event.getWinners();
             List<Image> actualImages = winners.getActualImages();
             actualImages.add(theImage);
             eventWinnerPicsUploadsAvailable = 10 - this.eventsWinnerPics.size();
             }
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.events.EventsController#deleteWinnerPicture(nz.co.selwynequestriancentre.model.entity.Image)
             */
             @Override
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public void deleteEventWinnerPicture(Image image) {
             Images winners = this.event.getWinners();
             List<Image> actualImages = winners.getActualImages();
             actualImages.remove(image);
             // Orphaned Image
             entityManager.remove(image);
             this.eventsWinnerPics = this.event.getWinners().getActualImages();
             eventWinnerPicsUploadsAvailable = 10 - this.eventsWinnerPics.size();
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.events.EventsController#listenerForClassEntityPrizesPictureUploads(org.richfaces.event.UploadEvent)
             */
             @Override
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public void listenerForClassEntityPrizesPictureUploads(UploadEvent event) throws IOException {
             List<UploadItem> uploadedImages = event.getUploadItems();
             for (UploadItem eachItem : uploadedImages) {
             Image theImage = new Image();
             theImage.setImage(eachItem.getData());
             theImage.setName(eachItem.getFileName());
             String mime = guessMime(eachItem);
             if (mime != null) {
             theImage.setType(mime); // eachItem.getContentType() <- Always octet type
             }
             if (this.classEntity.getPrizes() == null) {
             Images images = new Images();
             images.setActualImages(new ArrayList<Image>());
             this.classEntity.setPrizes(images);
             }
             Images prizes = this.classEntity.getPrizes();
             List<Image> actualImages = prizes.getActualImages();
             actualImages.add(theImage);
             classEntityPrizePicsUploadsAvailable = 10 - this.classEntityPrizePics.size();
             }
             }
            
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.events.EventsController#deleteClassEntityPrizePicture(nz.co.selwynequestriancentre.model.entity.Image)
             */
             @Override
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public void deleteClassEntityPrizePicture(Image image) {
             Images prizes = this.classEntity.getPrizes();
             List<Image> actualImages = prizes.getActualImages();
             actualImages.remove(image);
             // Orphaned Image
             entityManager.remove(image);
             this.classEntityPrizePics = this.classEntity.getPrizes().getActualImages();
             classEntityPrizePicsUploadsAvailable = 10 - this.classEntityPrizePics.size();
             }
            
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.events.EventsController#listenerForClassEntityWinnersPictureUploads(org.richfaces.event.UploadEvent)
             */
             @Override
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public void listenerForClassEntityWinnersPictureUploads(UploadEvent event) throws IOException {
             List<UploadItem> uploadedImages = event.getUploadItems();
             for (UploadItem eachItem : uploadedImages) {
             Image theImage = new Image();
             theImage.setImage(eachItem.getData());
             theImage.setName(eachItem.getFileName());
             String mime = guessMime(eachItem);
             if (mime != null) {
             theImage.setType(mime); // eachItem.getContentType() <- Always octet type
             }
             if (this.classEntity.getWinners() == null) {
             Images images = new Images();
             images.setActualImages(new ArrayList<Image>());
             this.classEntity.setWinners(images);
             }
             Images winners = this.classEntity.getWinners();
             List<Image> actualImages = winners.getActualImages();
             actualImages.add(theImage);
             classEntityWinnerPicsUploadsAvailable = 10 - this.classEntityWinnerPics.size();
             }
             }
            
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.events.EventsController#deleteClassEntityWinnerPicture(nz.co.selwynequestriancentre.model.entity.Image)
             */
             @Override
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public void deleteClassEntityWinnerPicture(Image image) {
             Images winners = this.classEntity.getWinners();
             List<Image> actualImages = winners.getActualImages();
             actualImages.remove(image);
             // Orphaned Image
             entityManager.remove(image);
             this.classEntityWinnerPics = this.classEntity.getWinners().getActualImages();
             classEntityWinnerPicsUploadsAvailable = 10 - this.classEntityWinnerPics.size();
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#cancel()
             */
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             @Override
             @End
             public String cancel() {
             log.info(">cancel");
             log.info("<cancel");
             this.event = null;
             this.eventsPrizePics = null;
             return "home";
             }
            
             /* (non-Javadoc)
             * @see nz.co.selwynequestriancentre.action.eventsManagement.EventsManagementController#destroy()
             */
             @Remove
             @Destroy
             @Override
             @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
             public void destroy() {
             log.info("> destory");
             log.info("< destory");
             }
            
            }
            
            


            • 3. Re: reattaching entities to stop detached entity exception
              Nick Belaevski Master

              Thank you, Tony! Let us check why this happens...

              • 4. Re: reattaching entities to stop detached entity exception
                Tony Herstell Master

                Might as well add this:

                Some of the .xhtml showing how the component was used...


                createUpdateEvent.xhtml

                <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
                 xmlns:s="http://jboss.com/products/seam/taglib" xmlns:a4j="http://richfaces.org/a4j"
                 xmlns:rich="http://richfaces.org/rich"
                 template="/WEB-INF/pages/templateCleanWithMenuWithConversations.xhtml">
                
                 <!-- content -->
                 <ui:define name="template_title">
                 <s:fragment rendered="#{mode == 'CREATE'}">
                 <h:outputText value="#{messages.events_create_event_page}" />
                 </s:fragment>
                 <s:fragment rendered="#{mode == 'UPDATE'}">
                 <h:outputText value="#{messages.events_update_event_page}" />
                 </s:fragment>
                 </ui:define>
                
                 <ui:define name="template_content">
                
                 <div id="events_form" class="general_form">
                
                 <f:view>
                
                 <a4j:outputPanel id="eventCreateUpdatePanel">
                
                 <a4j:form id="eventCreateUpdatePanelForm">
                
                 <br/>
                 <br/>
                
                 <fieldset class="general_form_fieldset">
                
                 <legend class="general_form_legend">
                 <s:fragment rendered="#{mode == 'CREATE'}">
                 <h:outputText value="#{messages.events_create_event_page}" />
                 </s:fragment>
                 <s:fragment rendered="#{mode == 'UPDATE'}">
                 <h:outputText value="#{messages.events_update_event_page}" />
                 </s:fragment>
                 </legend>
                
                 <a4j:include viewId="/WEB-INF/pages/events/eventFieldsEditable.xhtml" />
                
                 <br/>
                
                 <a4j:include viewId="/WEB-INF/pages/events/eventPrizesAreaEditable.xhtml" />
                
                 <br/>
                
                 <a4j:include viewId="/WEB-INF/pages/events/eventWinnersAreaEditable.xhtml" />
                
                 </fieldset>
                
                 <div class="general_form_buttons">
                 <a4j:commandButton styleClass="general_form_button" action="#{eventsController.backToEntityList}"
                 value="#{messages.general_button_back}" immediate="true" type="submit">
                 </a4j:commandButton>
                 <a4j:commandButton styleClass="general_form_button" id="eventsActionEventAttempt" type="submit"
                 value="#{messages.general_button_save}" rendered="#{mode == 'CREATE'or mode == 'UPDATE'}"
                 action="#{eventsController.saveEvent}" onclick="this.disabled=true"
                 oncomplete="this.disabled=false" limitToList="true"
                 reRender="eventCreateUpdatePanel, eventsActionAttemptMessages">
                 </a4j:commandButton>
                 </div>
                
                 <div>
                 <rich:message id="eventsActionAttemptMessages" errorClass="error" warnClass="warn"
                 infoClass="info" for="eventsActionEventAttempt"
                 rendered="#{mode == 'CREATE'or mode == 'UPDATE'}"/>
                 </div>
                
                 </a4j:form>
                
                 </a4j:outputPanel>
                
                 </f:view>
                
                 </div>
                
                 <a4j:status>
                 <f:facet name="start">
                 <h:graphicImage styleClass="page_foot_image" value="/images/ajax/animated_horse.gif" height="50" />
                 </f:facet>
                 </a4j:status>
                
                 <a4j:log />
                
                 </ui:define>
                 <!-- content -->
                
                </ui:composition>
                



                eventFieldsEditable.xhtml
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <ui:composition xmlns:c="http://java.sun.com/jstl/core" xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:s="http://jboss.com/products/seam/taglib" xmlns:a4j="http://richfaces.org/a4j"
                 xmlns:rich="http://richfaces.org/rich">
                
                 <br/>
                
                 <!-- ***********
                 Description
                 *********** -->
                 <s:decorate id="entity_event_description_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_description_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <h:inputText id="entity_event_description" value="#{event.description}" required="true"
                 title="#{messages.entity_event_description_tooltip}" size="70">
                 </h:inputText>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_description_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Publicised
                 *********** -->
                 <s:decorate id="entity_event_publicised_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_publicised_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <h:selectBooleanCheckbox id="entity_event_publicised" value="#{event.publicised}"
                 title="#{messages.entity_event_publicised_tooltip}" />
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_publicised_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Graded
                 *********** -->
                 <s:decorate id="entity_event_graded_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_graded_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <h:selectBooleanCheckbox id="entity_event_graded" value="#{event.graded}"
                 title="#{messages.entity_event_graded_tooltip}" />
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_graded_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Allowing External Emails
                 *********** -->
                 <s:decorate id="entity_event_allowing_external_emails_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_allowing_external_emails_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <h:selectBooleanCheckbox id="entity_event_allowing_external_emails" value="#{event.allowingExternalEmails}"
                 title="#{messages.entity_event_allowing_external_emails_tooltip}" />
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_allowing_external_emails_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- *******
                 Ground Fees
                 ********* -->
                 <s:decorate id="entity_event_cost_of_ground_fee_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_cost_of_ground_fee_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <h:inputText id="entity_event_cost_of_ground_fee" value="#{event.costOfGroundFee}" required="true"
                 title="#{messages.entity_event_cost_of_ground_fee_tooltip}">
                 <f:convertNumber
                 maxFractionDigits="2"
                 groupingUsed="true"
                 currencySymbol="$"
                 maxIntegerDigits="7"
                 type="currency"/>
                 </h:inputText>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_cost_of_ground_fee_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Entries Description
                 *********** -->
                 <s:decorate id="entity_event_entry_description_decorator" template="../editOfSeamTextArea.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_entry_description_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <ui:include src="/WEB-INF/pages/editorTemplate.xhtml">
                 <ui:param name="serversideVariable" value="#{event.entryDescription}"/>
                 </ui:include>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_entry_description_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Rules Description
                 *********** -->
                 <s:decorate id="entity_event_rules_description_decorator" template="../editOfSeamTextArea.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_rules_description_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <ui:include src="/WEB-INF/pages/editorTemplate.xhtml">
                 <ui:param name="serversideVariable" value="#{event.rulesDescription}"/>
                 </ui:include>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_rules_description_hint}" />
                 </ui:define>
                 </s:decorate>
                
                
                 <!-- ***********
                 Wet Weather Plan
                 *********** -->
                 <s:decorate id="entity_event_wet_weather_plan_description_decorator" template="../editOfSeamTextArea.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_wet_weather_plan_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <ui:include src="/WEB-INF/pages/editorTemplate.xhtml">
                 <ui:param name="serversideVariable" value="#{event.wetWeatherPlan}"/>
                 </ui:include>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_wet_weather_plan_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Entries Close Date
                 *********** -->
                 <s:decorate id="entity_event_entries_close_date_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_entries_close_date_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <rich:calendar value="#{event.entriesCloseDate}" ajaxSingle="true"
                 id="entity_event_entries_close_date" popup="true" currentDate="#{event.entriesCloseDate}"
                 datePattern="dd MMMM yyyy" inputSize="30" showWeeksBar="false" required="true">
                 </rich:calendar>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_entries_close_date_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Sponsors
                 *********** -->
                 <s:decorate id="entity_event_sponsors_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_sponsors_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <rich:pickList value="#{event.sponsors}" sourceListWidth="300px" targetListWidth="300px">
                 <s:selectItems value="#{availableUsers}" var="eachUser" label="#{eachUser.surname} , #{eachUser.firstname}"/>
                 <s:convertEntity/>
                 </rich:pickList>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_sponsors_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Sponsor Description
                 *********** -->
                 <s:decorate id="entity_event_sponsor_description_decorator" template="../editOfSeamTextArea.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_sponsor_description_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <ui:include src="/WEB-INF/pages/editorTemplate.xhtml">
                 <ui:param name="serversideVariable" value="#{event.sponsorDescription}"/>
                 </ui:include>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_sponsor_description_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Organisers
                 *********** -->
                 <s:decorate id="entity_event_organisers_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_organisers_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <rich:pickList value="#{event.organisers}" sourceListWidth="300px" targetListWidth="300px">
                 <s:selectItems value="#{availableUsers}" var="eachUser" label="#{eachUser.surname} , #{eachUser.firstname}"/>
                 <s:convertEntity/>
                 </rich:pickList>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_organisers_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Judges
                 *********** -->
                 <s:decorate id="entity_event_judges_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_judges_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <rich:pickList value="#{event.judges}" sourceListWidth="300px" targetListWidth="300px">
                 <s:selectItems value="#{availableUsers}" var="eachUser" label="#{eachUser.surname} , #{eachUser.firstname}"/>
                 <s:convertEntity/>
                 </rich:pickList>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_judges_hint}" />
                 </ui:define>
                 </s:decorate>
                
                
                 <!-- ***********
                 Scorers
                 *********** -->
                 <s:decorate id="entity_event_scorers_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_scorers_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <rich:pickList value="#{event.scorers}" sourceListWidth="300px" targetListWidth="300px">
                 <s:selectItems value="#{availableUsers}" var="eachUser" label="#{eachUser.surname} , #{eachUser.firstname}"/>
                 <s:convertEntity/>
                 </rich:pickList>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_scorers_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Helpers
                 *********** -->
                 <s:decorate id="entity_event_helpers_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_helpers_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <rich:pickList value="#{event.helpers}" sourceListWidth="300px" targetListWidth="300px">
                 <s:selectItems value="#{availableUsers}" var="eachUser" label="#{eachUser.surname} , #{eachUser.firstname}"/>
                 <s:convertEntity/>
                 </rich:pickList>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_helpers_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Secretaries
                 *********** -->
                 <s:decorate id="entity_event_secretaries_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_secretaries_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <rich:pickList value="#{event.secretaries}" sourceListWidth="300px" targetListWidth="300px">
                 <s:selectItems value="#{availableUsers}" var="eachUser" label="#{eachUser.surname} , #{eachUser.firstname}"/>
                 <s:convertEntity/>
                 </rich:pickList>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_secretaries_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Technical Delegates
                 *********** -->
                 <s:decorate id="entity_event_technical_delegates_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_technical_delegates_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <rich:pickList value="#{event.technicalDelegates}" sourceListWidth="300px" targetListWidth="300px">
                 <s:selectItems value="#{availableUsers}" var="eachUser" label="#{eachUser.surname} , #{eachUser.firstname}"/>
                 <s:convertEntity/>
                 </rich:pickList>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_technical_delegates_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Rules Officers
                 *********** -->
                 <s:decorate id="entity_event_technical_rules_officers_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_rules_officers_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <rich:pickList value="#{event.rulesOfficers}" sourceListWidth="300px" targetListWidth="300px">
                 <s:selectItems value="#{availableUsers}" var="eachUser" label="#{eachUser.surname} , #{eachUser.firstname}"/>
                 <s:convertEntity/>
                 </rich:pickList>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_rules_officers_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Ground Jurors
                 *********** -->
                 <s:decorate id="entity_event_technical_ground_jurors_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_ground_jurors_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <rich:pickList value="#{event.groundJurors}" sourceListWidth="300px" targetListWidth="300px">
                 <s:selectItems value="#{availableUsers}" var="eachUser" label="#{eachUser.surname} , #{eachUser.firstname}"/>
                 <s:convertEntity/>
                 </rich:pickList>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_ground_jurors_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Catering
                 *********** -->
                 <s:decorate id="entity_event_technical_catering_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_catering_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <rich:pickList value="#{event.catering}" sourceListWidth="300px" targetListWidth="300px">
                 <s:selectItems value="#{availableUsers}" var="eachUser" label="#{eachUser.surname} , #{eachUser.firstname}"/>
                 <s:convertEntity/>
                 </rich:pickList>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_catering_hint}" />
                 </ui:define>
                 </s:decorate>
                
                 <!-- ***********
                 Press
                 *********** -->
                 <s:decorate id="entity_event_technical_press_decorator" template="../edit.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{messages.entity_event_press_label}" />
                 </ui:define>
                 <ui:define name="content">
                 <div>
                 <rich:pickList value="#{event.press}" sourceListWidth="300px" targetListWidth="300px">
                 <s:selectItems value="#{availableUsers}" var="eachUser" label="#{eachUser.surname} , #{eachUser.firstname}"/>
                 <s:convertEntity/>
                 </rich:pickList>
                 </div>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{messages.entity_event_press_hint}" />
                 </ui:define>
                 </s:decorate>
                
                </ui:composition>
                




                edit.xhtml
                <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
                 xmlns:s="http://jboss.com/products/seam/taglib">
                
                 <table class="edit_template_area">
                 <tr>
                 <td class="edit_template_label_area" >
                 <s:label styleClass="#{invalid?'error':''}">
                 <ui:insert name="label" />
                 </s:label>
                 </td>
                 <td class="edit_template_tag_area">
                 <span >
                 <h:outputText styleClass="mandatory" value="#{messages.general_mandatory_tag}" rendered="#{required}"/>
                 </span>
                 </td>
                 <td class="edit_template_field_area">
                 <table>
                 <tr>
                 <td>
                 <ui:insert name="header" />
                 </td>
                 </tr>
                 <tr>
                 <td>
                 <span class="edit_template_content_area #{invalid?'errorblock':'noerrorblock'}">
                 <s:validateAll>
                 <ui:insert name="content" />
                 </s:validateAll>
                 </span>
                 </td>
                 </tr>
                 <tr>
                 <td>
                 <span class="edit_template_error_area">
                 <center>
                 <ui:insert name="error_messages" >
                 <s:message styleClass="edit_template_error error" />
                 </ui:insert>
                 </center>
                 </span>
                 </td>
                 </tr>
                 <tr>
                 <td>
                 <ui:insert name="preview" />
                 </td>
                 </tr>
                 <tr>
                 <td>
                 <span class="edit_template_hint_area">
                 <ui:insert name="hint"/>
                 </span>
                 </td>
                 </tr>
                 </table>
                 </td>
                 </tr>
                 </table>
                
                </ui:composition>
                
                




                For viewing
                eventFieldsNotEditable.xhtml
                 <!-- ****
                 Sponsors
                 ****** -->
                 <ui:include src="./associatedUserListNotEditable.xhtml">
                 <ui:param name="decoratorId" value="entity_event_sponsor_decorator"/>
                 <ui:param name="associateLabel" value="#{messages.entity_event_sponsor_label}"/>
                 <ui:param name="associateList" value="#{event.sponsors}"/>
                 <ui:param name="associateHint" value="#{messages.entity_event_sponsor_hint}"/>
                 </ui:include>
                



                associatedUserListNotEditable.xhtml
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <ui:composition xmlns:c="http://java.sun.com/jstl/core" xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:s="http://jboss.com/products/seam/taglib" xmlns:a4j="http://richfaces.org/a4j"
                 xmlns:rich="http://richfaces.org/rich">
                
                
                 <!-- ************
                 Associated User
                 ************** -->
                 <s:decorate id="#{decoratorId}" template="../view.xhtml">
                 <ui:define name="label">
                 <h:outputText value="#{associateLabel}" />
                 </ui:define>
                 <ui:define name="content">
                 <h:outputText value="#{messages.user_list_no_users}" rendered="#{empty associateList}"/>
                 <rich:dataTable id="associated_user_list" value="#{associateList}" var="eachAssociatedUser" sortMode="multi"
                 columnClasses="center" width="100%" rendered="#{not empty associateList}"
                 onRowMouseOver="this.style.backgroundColor='#F8F8F8'"
                 onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
                 <f:facet name="header">
                 <h:outputText value="#{associateLabel}" />
                 </f:facet>
                 <rich:column id="avatar" label="Avatar" width="75">
                 <f:facet name="header">
                 <h:outputText value="Avatar" />
                 </f:facet>
                 <s:graphicImage rendered="#{eachAssociatedUser.avatar ne null}" value="#{eachAssociatedUser.avatar.image}" >
                 <s:transformImageSize width="75" maintainRatio="true"/>
                 </s:graphicImage>
                 </rich:column>
                 <rich:column id="surname" label="Surname" width="75">
                 <f:facet name="header">
                 <h:outputText value="Surname" />
                 </f:facet>
                 <h:outputText value="#{eachAssociatedUser.surname}" />
                 </rich:column>
                 <rich:column id="firstname" label="Firstname" width="75">
                 <f:facet name="header">
                 <h:outputText value="Firstname" />
                 </f:facet>
                 <h:outputText value="#{eachAssociatedUser.firstname}" />
                 </rich:column>
                 <rich:column id="email" label="Email" width="250">
                 <f:facet name="header">
                 <h:outputText value="Email" />
                 </f:facet>
                 <h:outputText value="#{eachAssociatedUser.email}" />
                 </rich:column>
                 <rich:column id="homePhone" label="Home Phone" width="150">
                 <f:facet name="header">
                 <h:outputText value="Home Phone" />
                 </f:facet>
                 <h:outputText value="#{eachAssociatedUser.homePhone}" />
                 </rich:column>
                 <rich:column id="mobilePhone" label="Mobile Phone">
                 <f:facet name="header">
                 <h:outputText value="Mobile Phone" />
                 </f:facet>
                 <h:outputText value="#{eachAssociatedUser.mobilePhone}" />
                 </rich:column>
                 <rich:column id="phoneContactOk" label="Phone Contact Ok" width="30">
                 <f:facet name="header">
                 <h:outputText value="Phone Contact Ok" />
                 </f:facet>
                 <s:graphicImage rendered="#{eachAssociatedUser.phoneContactOk}" fileName="tick" url="/images/tick.gif" />
                 <s:graphicImage rendered="#{not eachAssociatedUser.phoneContactOk}" fileName="cross" url="/images/cross.gif" />
                 </rich:column>
                 </rich:dataTable>
                 </ui:define>
                 <ui:define name="hint">
                 <s:formattedText value="#{associateHint}" />
                 </ui:define>
                 </s:decorate>
                
                </ui:composition>
                


                • 5. Re: reattaching entities to stop detached entity exception
                  Tony Herstell Master

                  I had to do this for results returned from a h:selectOneMenu as well (as well as override the equals routine to get rid of the Invalid problem).