[JBoss Seam] - Re: Trouble with @DataModelSelection
by 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>
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4031241#4031241
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4031241
19Â years, 1Â month
[JBoss Seam] - Re: Trouble with @DataModelSelection
by 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.
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
19Â years, 1Â month