4 Replies Latest reply on Aug 8, 2006 10:21 AM by Samuel Mendenhall

    can't quite get push-style mvc working

    Samuel Mendenhall Apprentice

      I am trying to emulate the "push"-style section 1.10.3 in Chapter 1. Seam Tutorial.

      When I load the page I want data to get pushed to initially, nothing happens in console and the data is not loaded, despite the page loading as normal. So I am assuming the EJB is never actually getting called. Even if I am not actually Outjecting anything to the view, when the findFirstPage method gets called in the EJB, it should be outputing debug text to the console, which it never does.

      So what I want to do is for a user to go to /showGroups.seam, which is mapped to the file showGroups.jsp, and for an arbitrary list of default groups to be pushed to the view, and the page will also allow the user to search for groups. But a big part of the functionality is showing those initial groups.

      Here is my code:

      pages.xml

      <pages>
       <page view-id="/showGroups.seam">#{groupFinder.findFirstPage}</page>
      </pages>
      



      GroupFinderBean.java with non relevant code removed
      @Name("groupFinder")
      @Stateful
      @Scope(ScopeType.SESSION)
      public class GroupFinderBean implements GroupFinder {
      
       @Logger
       private Log log;
      
       @DataModel
       private List<Group> groupList;
      
      
       @PersistenceContext
       private EntityManager entityManager;
      
       private void executeQuery() {
       Map<String, Object> parameters = new HashMap<String, Object>();
       StringBuffer queryString = new StringBuffer();
      
       log.info("searchColumns: " + Arrays.asList(searchColumns));
      
      
       //*******************************************************//
       // Handle case when a user clicks on a letter
       //*******************************************************//
       if(start != null && !start.equals("")) {
       queryString.append(" or group.name" + " like :value or group.name like :valuetwo ");
       parameters.put("value", start + "%");
       parameters.put("valuetwo", start.toLowerCase() + "%");
       }
      
      
       //************************************************************//
       // Handle case when a user is searching via the search field
       //************************************************************//
       if(searchField != null ) {
       int x = 0;
       for(String searchColumn : searchColumns) {
       if(searchField.contains("%")) {
       queryString.append(" or group." + searchColumn + " like :" + searchColumn);
       } else {
       queryString.append(" or group." + searchColumn + " = :" + searchColumn);
       }
       parameters.put( searchColumn, searchField );
       x++;
       }
       }
      
       //************************************************************//
       // Handle case when a user enters no input, but clicks search
       //************************************************************//
       if(queryString.length() == 0) {
       queryString.append("select group from Group group");
       } else {
       queryString.delete(0, 3).insert(0, "select group from Group group where ");
       }
      
       if(order!=null) {
       queryString.append(" order by group.").append(order);
       if (descending) queryString.append(" desc");
       }
      
      
       log.info("searchField: " + searchField + " queryString: \n\n" + queryString + "\n\n");
      
       Query query = entityManager.createQuery(queryString.toString());
       for (Entry <String, Object> param : parameters.entrySet()) {
       query.setParameter( param.getKey(), param.getValue() );
       }
       groupList = (List<Group>) query.setMaxResults(pageSize)
       .setFirstResult(pageSize*pageNumber)
       .getResultList();
       }
      
       public String findFirstPage() {
       log.info("Find First Page");
       pageNumber=0;
       executeQuery();
       return null;
       }
      }
      



      web.xml
      <servlet-mapping>
       <servlet-name>Faces Servlet</servlet-name>
       <url-pattern>*.seam</url-pattern>
      </servlet-mapping>
      



      I'm thinking it may have something to do with the scope of the EJB, as the EJB in the Blog example is Stateless, mine is Stateful.

      Thanks for the help.