This content has been marked as final.
Show 4 replies
-
1. Re: Trouble with @DataModelSelection
henrik.lindberg Mar 23, 2007 6:37 PM (in response to henrik.lindberg)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. -
2. Re: Trouble with @DataModelSelection
henrik.lindberg Mar 23, 2007 6:38 PM (in response to henrik.lindberg)Here is the local interface (sans imports and headers):
@Local 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 Mar 23, 2007 6:42 PM (in response to henrik.lindberg)And here is the 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:s="http://jboss.com/products/seam/taglib" 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:a4j="https://ajax4jsf.dev.java.net/ajax" xmlns:rich="http://richfaces.ajax4jsf.org/rich" template="layout/template.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> <div class="Divider2" id="cspaces-topDivider"/> <f:view> <!-- ADDING NEW SPACE --> <div id="addSpaceBox"><h:form id="addSpaceForm"> <s:validateAll> <h:outputLabel for="spaceInput">Wanted Public Space Name:</h:outputLabel> <h:inputText styleClass="InputField" id="spaceInput" value="#{userSpaces.spaceInput}" required="true" maxlength="93" /> <h:commandButton type="submit" value="Add Space" action="#{userSpaces.addSpace}" image="/img/create.new.space.grey.btn.png" /> <h:message for="spaceInput" /> <h:messages globalOnly="true" /> </s:validateAll> </h:form></div> <div class="Divider2" id="cspaces-bottomDivider"/> <h:outputText rendered="#{availableSpaces == null or not (availableSpaces.rowCount > 0)}" styleClass="warn" value="There are no spaces to display. Add wanted space(s) using the box above." /> <h:form id="spaceForm"> <h:dataTable id="space_list" styleClass="fence" value="#{availableSpaces}" var="p" rendered="#{availableSpaces != null and availableSpaces.rowCount > 0}" rowClasses="first,second" columnClasses="col1class,col2class" first="#{userSpaces.first}" rows="#{userSpaces.pageSize}"> <h:column> <f:facet name="header">name</f:facet> <s:link value="#{p.spaceName}" action="#{userSpaces.select(p)}" /> </h:column> <h:column> <f:facet name="header">created</f:facet> <h:outputText value="#{p.dateAdded}" /> </h:column> </h:dataTable> <rich:datascroller for="space_list" rendered="#{availableSpaces != null and availableSpaces.rowCount > 0}" maxPages="9" id="paginator" renderIfSinglePage="false" /> </h:form> </f:view> </ui:define> </ui:composition>
-
4. Re: Trouble with @DataModelSelection
henrik.lindberg Mar 23, 2007 8:21 PM (in response to henrik.lindberg)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...