1 Reply Latest reply on Nov 6, 2006 5:08 AM by Pete Muir

    The Same SelectItem Control on Multiple Pages...

    johnurban Newbie

      I need to put the same dropdown(selectitem) on multiple pages. I am using selectitems-1.1.0rc1. I have successfully place the dropdown on one screen. I am able to populate it and pull the selected value from it. Now, I need that same dropdown on another screen. In in my working screen, I use RoomServiceBean to call the DB and get a List:

       <h:selectOneMenu value="#{person.room}" converter="org.jboss.seam.EntityConverter" required="true">
       <f:selectItems value="#{rooms}" />
       <h:message for="room"/>
       </h:selectOneMenu>
      
      


      where room is an attribute of the entity bean person.

      Now my new screen looks like this:

      
       <h:selectOneMenu value="#{attendanceService.room}" converter="org.jboss.seam.EntityConverter" required="true">
       <f:selectItems value="#{rooms}" />
       </h:selectOneMenu>
      
      


      So "rooms" gets looked up in Seam and populated by the RoomServiceBean, b/c thats where rooms lives. But "attendanceService.room" seems to be conflicting with another room somehow.

      Here is RoomServiceBean.java:

       package testSeam;
      
      // Generated Oct 6, 2006 12:55:26 AM by Hibernate Tools 3.2.0.beta7
      
      import java.util.ArrayList;
      import java.util.Iterator;
      import java.util.Map;
      import java.util.List;
      import javax.ejb.Remove;
      import javax.ejb.Stateless;
      import javax.ejb.Stateful;
      import javax.ejb.TransactionAttribute;
      import static javax.ejb.TransactionAttributeType.NOT_SUPPORTED;
      import javax.faces.application.FacesMessage;
      import javax.faces.context.FacesContext;
      import javax.faces.model.SelectItem;
      import javax.interceptor.Interceptors;
      import javax.persistence.EntityManager;
      
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.End;
      import org.jboss.seam.annotations.IfInvalid;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Outcome;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Factory;
      
      import org.jboss.seam.ejb.SeamInterceptor;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.selectitems.annotations.SelectItems;
      
      import org.hibernate.validator.Valid;
      
      @Name("roomService")
      @Stateless
      @Interceptors(SeamInterceptor.class)
      @CheckLoggedIn
      public class RoomServiceBean implements RoomService {
       @Logger
       private Log log;
      
       @In(create = true)
       private EntityManager entityManager;
      
       @In(required=false)
       private Login login;
      
       private Room room = new Room();
      
       @In(value="person", create=true)
       @Out
       private Person person = new Person();
      
       private String doneOutcome = "find";
      
       @In(required = false)
       private transient RoomFinder roomFinder;
      
       @In(create = true)
       private transient Map messages;
      
       private boolean isNew = true;
      
       @SelectItems(label="name", addNoSelectionLabel="Please select a room")
       private List<Room> rooms;
      
       @SelectItems(label="name", addNoSelectionLabel="Please select an organization")
       private List<Organization> organizations;
      
       @TransactionAttribute(NOT_SUPPORTED)
       public Person getPerson() {
       System.out.println("PersonEditorBean.getPerson|"+person);
       return person;
       }
      
       public void setPerson(Person person) {
       System.out.println("PersonEditorBean.setPerson|"+person);
       this.person = person;
       }
      
       @TransactionAttribute(NOT_SUPPORTED)
       public Room getRoom() {
       return room;
       }
      
       public void setRoom(Room room) {
       this.room = room;
       }
      
       @TransactionAttribute(NOT_SUPPORTED)
       public boolean isNew() {
       return isNew;
       }
      
       public void setNew(boolean isNew) {
       this.isNew = isNew;
       }
      
       public void setDoneOutcome(String outcome) {
       doneOutcome = outcome;
       }
      
       @SuppressWarnings("unchecked")
       @Factory("rooms")
       @LoggedIn
       public void buildRooms() {
       log.info("top of buildRooms()");
       Users loggedInUser = login.getInstance();
      
       StringBuffer queryString = new StringBuffer();
       queryString.append("select rm from Room rm ");
       queryString.append(" where rm.organizationId = "+loggedInUser.getOrganizationId());
      
       rooms = entityManager.createQuery(queryString.toString()).getResultList();
       log.info("Room list has " + rooms.size() + " entries");
       }
      
       @SuppressWarnings("unchecked")
       @Factory("organizations")
       public void buildOrganizations() {
       log.info("top of buildOrganizations()");
       organizations = entityManager.createQuery("select org from Organization org").getResultList();
       log.info("Organization list has " + organizations.size() + " entries");
       }
      
       @Begin(join = true)
       @IfInvalid(outcome = Outcome.REDISPLAY)
       @LoggedIn
       public String addNewPerson() {
       log.info("... about to call entityManager.find:"+person+"|"+person.getId());
      
       Users loggedInUser = login.getInstance();
      
       Organization org = new Organization();
       org.setId(loggedInUser.getOrganizationId());
       person.setOrganization(org);
      
       if (entityManager.find(Person.class, person.getId()) != null) {
       log.info("top of RoomServieBean.addNewPerson()");
       FacesContext.getCurrentInstance().addMessage( null, new FacesMessage(messages.get("Person_id") + " " + messages.get("AlreadyExists")));
       return null;
       }
      
       entityManager.merge(person);
       isNew = false;
       refreshFinder();
       FacesContext.getCurrentInstance().addMessage( null, new FacesMessage("Person added successfully..."));
       return "uPersonCheckin.jsp";
       }
      
       @IfInvalid(outcome = Outcome.REDISPLAY)
       public String update() {
       refreshFinder();
       return null;
       }
      
       @End(ifOutcome = "find")
       public String delete() {
       entityManager.remove(room);
       refreshFinder();
       return doneOutcome;
       }
      
       @End(ifOutcome = "find")
       public String done() {
       if (!isNew)
       entityManager.refresh(room);
       return doneOutcome;
       }
      
       private void refreshFinder() {
       if (roomFinder != null)
       roomFinder.refresh();
       }
      }
      
      


      Here is AttendanceServicesBean.java:

      package testSeam;
      
      // Generated Sep 23, 2006 1:30:01 PM by Hibernate Tools 3.2.0.beta7
      
      import static javax.ejb.TransactionAttributeType.NOT_SUPPORTED;
      
      import java.util.HashMap;
      import java.util.List;
      import java.util.Map;
      import java.util.Map.Entry;
      import java.util.Random;
      import java.util.Date;
      import javax.ejb.Remove;
      import javax.ejb.Stateless;
      import javax.ejb.TransactionAttribute;
      import javax.interceptor.Interceptors;
      import javax.persistence.EntityManager;
      import javax.persistence.Query;
      
      import org.apache.commons.lang.RandomStringUtils;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.annotations.End;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.RequestParameter;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.datamodel.DataModelSelection;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.log.Log;
      
      import org.jboss.seam.ejb.SeamInterceptor;
      
      @Name("attendanceService")
      @Stateless
      @Scope(ScopeType.STATELESS)
      @Interceptors(SeamInterceptor.class)
      @CheckLoggedIn
      public class AttendanceServiceBean implements AttendanceService {
      
       @Logger
       private Log log;
      
       @In(required=false)
       private Login login;
      
       private int pageNumber = 0;
       private int pageSize = 20;
       private boolean registered = false;
      
       @DataModel
       private List<Attendance> attendanceList;
      
       @In(create = true)
       private EntityManager entityManager;
      
       @In(create = true)
       private Room room;
      
       private String order;
       private boolean descending = false;
      
       @RequestParameter
       private String orderBy;
       private int id;
      
       public void setPageSize(int size) {
       pageSize = size;
       }
      
       public int getPageSize() {
       return pageSize;
       }
      
       public boolean isPreviousPage() {
       return attendanceList != null && pageNumber > 0;
       }
      
       public boolean isNextPage() {
       return attendanceList != null && attendanceList.size() == pageSize;
       }
      
       public void attendanceLookup() {
      log.info("inside attendanceLookup");
       Map<String, Object> parameters = new HashMap<String, Object>();
       StringBuffer queryString = new StringBuffer();
      
       queryString.append(" and roomId = :roomId");
       parameters.put("roomId", room.getId());
      
       if (queryString.length() == 0) {
       queryString.append("select atnd from Attendance atnd");
       } else {
       queryString.delete(0, 4).insert(0,
       "select atnd from Attendance atnd where");
       }
      
       log.info("sql:"+queryString.toString());
      
       Query query = entityManager.createQuery(queryString.toString());
       for (Entry<String, Object> param : parameters.entrySet()) {
       query.setParameter(param.getKey(), param.getValue());
       }
       attendanceList = (List<Attendance>) query.setMaxResults(pageSize)
       .setFirstResult(pageSize * pageNumber).getResultList();
       }
      
       public String findFirstPage() {
       pageNumber = 0;
       attendanceLookup();
       return null;
       }
      
       public String findNextPage() {
       pageNumber++;
       attendanceLookup();
       return null;
       }
      
       public String findPreviousPage() {
       pageNumber--;
       attendanceLookup();
       return null;
       }
      
       public void refresh() {
       if (attendanceList != null)
       attendanceLookup();
       }
      
       public String clear() {
       attendanceList = null;
       // example = new Person();
       return null;
       }
      
       public String reorder() {
       if (orderBy.equals(order)) {
       descending = !descending;
       } else {
       descending = false;
       }
       order = orderBy;
       attendanceLookup();
       return null;
       }
      
       @LoggedIn
       public String edit() {
       return "/uEditPerson.jsp";
       }
      }
      


      I get this exception when trying to render my new page:


      javax.faces.el.PropertyNotFoundException: Bean: $Proxy1061, property: room
      at org.apache.myfaces.el.PropertyResolverImpl.getPropertyDescriptor(PropertyResolverImpl.java:445)
      at org.apache.myfaces.el.PropertyResolverImpl.getPropertyDescriptor(PropertyResolverImpl.java:416)
      at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:379)
      at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:71)
      at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:532)
      at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
      at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:378)
      at javax.faces.component.UIOutput.getValue(UIOutput.java:75)
      at org.apache.myfaces.renderkit.html.HtmlRendererUtils.getSubmittedOrSelectedValuesAsSet(HtmlRendererUtils.java:314)
      at org.apache.myfaces.renderkit.html.HtmlRendererUtils.internalRenderSelect(HtmlRendererUtils.java:290)
      at org.apache.myfaces.renderkit.html.HtmlRendererUtils.renderMenu(HtmlRendererUtils.java:246)
      at org.apache.myfaces.renderkit.html.HtmlMenuRendererBase.encodeEnd(HtmlMenuRendererBase.java:54)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:331)
      at javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java:349)
      at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:253)
      at org.apache.jsp.uQuickRoomReport_jsp._jspx_meth_h_selectOneMenu_0(uQuickRoomReport_jsp.java:297)
      at org.apache.jsp.uQuickRoomReport_jsp._jspx_meth_h_form_0(uQuickRoomReport_jsp.java:242)
      at org.apache.jsp.uQuickRoomReport_jsp._jspx_meth_f_view_0(uQuickRoomReport_jsp.java:189)
      at org.apache.jsp.uQuickRoomReport_jsp._jspService(uQuickRoomReport_jsp.java:97)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
      at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:415)
      at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:234)
      at org.jboss.seam.jsf.SeamViewHandler.renderView(SeamViewHandler.java:59)
      at org.jboss.seam.jsf.SeamViewHandler.renderView(SeamViewHandler.java:59)
      at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:352)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:45)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:613)
      21:54:13,617 ERROR [SeamExceptionFilter] uncaught exception handled by Seam
      javax.servlet.ServletException: Bean: $Proxy1061, property: room
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:121)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:45)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:613)
      21:54:13,618 INFO [SeamExceptionFilter] killing transaction
      21:54:13,622 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
      javax.faces.FacesException: Bean: $Proxy1061, property: room
      at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:421)
      at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:234)
      at org.jboss.seam.jsf.SeamViewHandler.renderView(SeamViewHandler.java:59)
      at org.jboss.seam.jsf.SeamViewHandler.renderView(SeamViewHandler.java:59)
      at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:352)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:45)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:613)
      Caused by: org.apache.jasper.JasperException: Bean: $Proxy1061, property: room
      at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
      at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:415)
      ... 26 more