4 Replies Latest reply on Mar 23, 2007 8:21 PM by henrik lindberg

    Trouble with @DataModelSelection

    henrik lindberg Apprentice

      I am having trouble with using @DataModelSelection - I end up with an empty object when something is selected.

      I am using seam 1.2GA, and Ajax4JSF + Rich Faces.

      (Will post code as I am stuck)

      Greatful for any help or suggestions...

        • 1. Re: Trouble with @DataModelSelection
          henrik lindberg Apprentice

          Here is the action bean:

          @Restrict("#{s:hasRole('user')}") // Forces check that user is logged in
          public class UserSpacesAction implements UserSpacesLocal, Serializable
           private static final long serialVersionUID = -3722438832731142648L;
           private EntityManager em;
           private User m_currentUser;
           private String m_spaceInput;
           private List<PublishingSpace> m_availableSpaces;
           @Out(required = false)
           private PublishingSpace selectedSpace;
           private String m_first;
           private static int PAGESIZE = 10;
           private Log log;
           public void getAvailableSpaces()
           log.debug("Get User space for user #0", m_currentUser.getLogin());
           m_availableSpaces = em.createQuery(
           "SELECT DISTINCT s.publishingSpace FROM SpaceAccess s WHERE s.theUser = :user").setParameter("user",
           log.debug("Got a List back empty=#0", Boolean.valueOf(m_availableSpaces.isEmpty()));
           public PublishingSpace getSelectedSpace()
           return selectedSpace;
           public void setSelectedSpace(PublishingSpace space)
           selectedSpace = space;
           public String addSpace()
           // create the full "public.xxx" name and check that it is a
           // valid space name
           String tmpSpace = "public."+m_spaceInput;
           FacesMessages.instance().add("spaceInput", "Invalid space name");
           return null;
           // Check if space exists
           if(PublishingSpace.exists(em, tmpSpace))
           FacesMessages.instance().add("spaceInput", "Space name already taken - use something else.");
           return null;
           // Add objects
           log.debug("Adding space for public.#0", m_spaceInput);
           PublishingSpace p = new PublishingSpace("public."+m_spaceInput);
           p.setDateAdded(new Date());
           SpaceAccess sa = new SpaceAccess(m_currentUser,p, Boolean.TRUE);
           log.info("Added space #0 for user #1", p.getSpaceName(), m_currentUser.getLogin());
           // Clear this value for new input
           m_spaceInput = "";
           return null;
           public void setSpaceInput(String space)
           m_spaceInput = space;
           public String getSpaceInput()
           return m_spaceInput;
           public void select(PublishingSpace space)
           selectedSpace = space;
           log.info("selectedSpace=", space == null ? "null" : space.getSpaceName());
           public String nextPage()
           System.err.print("NEXT PAGE first="+m_first);
           if(m_availableSpaces != null)
           int tmp = getIntFirst() + PAGESIZE;
           if(tmp <= m_availableSpaces.size())
           return null;
           public String prevPage()
           setIntFirst(Math.max(0, getIntFirst() - PAGESIZE));
           return null;
           public String firstPage()
           return null;
           public String lastPage()
           if(m_availableSpaces != null)
           int lastIdx = m_availableSpaces.size() -1;
           if(lastIdx >= 0)
           int tmp = lastIdx / PAGESIZE;
           setIntFirst(tmp * PAGESIZE);
           return null;
           public String getFirst()
           return m_first == null ? "0" : m_first;
           public void setFirst(String first)
           m_first = first;
           private void setIntFirst(int first)
           m_first = String.valueOf(first);
           private int getIntFirst()
           return (m_first == null ? 0 :
           public int getPageSize()
           return PAGESIZE;
           public void destroy()
           System.out.print("USERSPACES-ACTION - destroyed");

          I experimented with some getters and setters of the data selection - but it did not make a difference - does not work either way.

          Also, it does not matter if I use the "addSpace" method to add new things - if I just render objects already in the database I have the same problem.
          The pagination code is there to support a view that is not converted to use a datascrooller/paginator.

          In this version of the select method I try to pass the selected thing as a parameter from the facelet. My previous attempt did not use that - it produced the same result.

          Will now post the remaining parts.

          • 2. Re: Trouble with @DataModelSelection
            henrik lindberg Apprentice

            Here is the local interface (sans imports and headers):

            public interface UserSpacesLocal
             public void destroy();
             public void getAvailableSpaces();
             public String getSpaceInput();
             public void setSpaceInput(String space);
             public String addSpace();
             public String nextPage();
             public String prevPage();
             public String firstPage();
             public String lastPage();
             public int getPageSize();
             public String getFirst();
             public void setFirst(String first);
             public void select(PublishingSpace selectedSpace);
             public void setSelectedSpace(PublishingSpace space);
             public PublishingSpace getSelectedSpace();

            • 3. Re: Trouble with @DataModelSelection
              henrik lindberg Apprentice

              And here is the xhtml:

              <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
              <ui:composition xmlns="http://www.w3.org/1999/xhtml"
               <ui:define name="title">Spaces page</ui:define>
               <ui:define name="body">
               <div id="wrap-cspaces">
               <img id="spacesHeading" src="/img/spaces.heading.png" />
               <a href="FAQ-spaces.seam"><img class="infoButton" id="spacesInfo"
               src="/img/info.button.png" /></a>
               <div class="Divider2" id="cspaces-topDivider"/>
               <!-- ADDING NEW SPACE -->
               <div id="addSpaceBox"><h:form id="addSpaceForm">
               <h:outputLabel for="spaceInput">Wanted Public Space Name:</h:outputLabel>
               maxlength="93" />
               <h:commandButton type="submit" value="Add Space"
               image="/img/create.new.space.grey.btn.png" />
               <h:message for="spaceInput" />
               <h:messages globalOnly="true" />
               <div class="Divider2" id="cspaces-bottomDivider"/>
               rendered="#{availableSpaces == null or not (availableSpaces.rowCount > 0)}"
               value="There are no spaces to display. Add wanted space(s) using the box above." />
               <h:form id="spaceForm">
               rendered="#{availableSpaces != null and availableSpaces.rowCount > 0}"
               <f:facet name="header">name</f:facet>
               <s:link value="#{p.spaceName}" action="#{userSpaces.select(p)}" />
               <f:facet name="header">created</f:facet>
               <h:outputText value="#{p.dateAdded}" />
               rendered="#{availableSpaces != null and availableSpaces.rowCount > 0}"

              • 4. Re: Trouble with @DataModelSelection
                henrik lindberg Apprentice

                Happy now!

                A manual clean up of deployment folders, rebuilding from scratch and restarting JBoss cured the problem.

                (And in case you have not spotted it - in the code above - the call to log in the select() method does not output anything because of a missing #0 in the template string - but that was also where I had my breakpoint - thought it worth mentioning...