Here is the action bean:

  | @Stateful
  | @Scope(SESSION)
  | @Name("userSpaces")
  | @TransactionAttribute(REQUIRED)
  | @Restrict("#{s:hasRole('user')}") // Forces check that user is logged in
  | public class UserSpacesAction implements UserSpacesLocal, Serializable
  | {
  | 
  |     private static final long serialVersionUID = -3722438832731142648L;
  | 
  |     @PersistenceContext
  |     private EntityManager em;
  | 
  |     @In("currentUser")
  |     private User m_currentUser;
  | 
  |     private String m_spaceInput;
  | 
  |     @SuppressWarnings("unused")
  |     @DataModel("availableSpaces")
  |     private List<PublishingSpace> m_availableSpaces;
  | 
  |     @SuppressWarnings("unused")
  |     @DataModelSelection
  |     @Out(required = false)
  |     private PublishingSpace selectedSpace;
  |     
  | 
  |     private String m_first;
  |     private static int PAGESIZE = 10;
  |     
  |     @Logger
  |     private Log log;
  | 
  |     @SuppressWarnings("unchecked")
  |     @Factory("availableSpaces")
  |     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",
  |                             m_currentUser).getResultList();
  |             
  |             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;
  |             if(!SpaceNameValidator.isSpaceNameValid(tmpSpace))
  |             {
  |                     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);
  |             em.persist(p);
  |             em.persist(sa);
  |             log.info("Added space #0 for user #1", p.getSpaceName(), 
m_currentUser.getLogin());
  |             getAvailableSpaces();
  |             lastPage();
  |             // 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())
  |                             setIntFirst(tmp);
  |             }
  |             return null;
  |     }
  |     public String prevPage()
  |     {
  |             setIntFirst(Math.max(0, getIntFirst() - PAGESIZE));
  |             return null;
  |     }
  |     public String firstPage()
  |     {
  |             setIntFirst(0);
  |             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 : 
  |                     Integer.parseInt(m_first));
  |     }
  |     public int getPageSize()
  |     {
  |             return PAGESIZE;
  |     }
  |     @Destroy
  |     @Remove
  |     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.

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

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4031238
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to