1 Reply Latest reply on Aug 3, 2010 12:22 AM by shavo26

    Newbie Seam DataModel cannot be cast to ArrayList

    demolina79

      I am new to SEAM trying out from a generated app some changes like implement a data selecitonemenu where i can show data from a table in a form,
      i am getting the following exception


      java.util.ArrayList cannot be cast to javax.faces.model.DataModel


      It may be something very basic but i havent found a good example for this, maybe someone can point me out to one. I am reading Seam in Action and Seam Framework from YUAN havent found one example like the one i am trying.


      This is my bean





          @Name("FuncionesAcciones")
          public class FuncionesAcciones {
           @Logger
           private Log log;
          
           @In
           StatusMessages statusMessages;
          
           @In
           protected EntityManager entityManager = null;
          
           @DataModelSelection
           @Out(required = false)
           protected Usuarios selectedUser;
          
           @DataModel
           @Out(required = false)
           protected List<Usuarios> listaUsers = null;
          
           public String view() {
            return "/AccionesEdit.xhtml";
           }
          
           @Factory("listaUsers")
           public void listarUsuarios() {
            List resultList = entityManager.createQuery(
                    "select idUsuarios from Usuarios")
              .getResultList();
            listaUsers = (List<Usuarios>) resultList;
          //  "select idUsuarios,NombreUsuario from Usuarios")
           }
          
           public void funcionesAcciones() {
            // implement your business logic here
            log.info("FuncionesAcciones.funcionesAcciones() action called");
            statusMessages.add("funcionesAcciones");
           }
          
           // add additional action methods
          
          }







      This is the part where i use it in the Facelet





             <s:decorate id="usuariosIdUsuariosField" value="#{FuncionesAcciones.selectedUser}"          template="layout/edit.xhtml">
                   <ui:define name="label">Usuario que Identifica Accion</ui:define>
                   <h:selectOneMenu  name="usuario" id="usuariosIdUsuarios" required="true"   value="Usuarios.nombreUsuario">
                      <f:selectItems var="_usuario" value ="#{listaUsers}" label="#{_usuario.NombreUsuario}"/>
                       <s:convertEnum/> 
                   </h:selectOneMenu>
                 </s:decorate>






      Someone can point me out in the right direction , i am new to SEAM somewhat middle experience in JAVA/Hibernate i come from PHP so the learning curve is apparently very hard right now as a beginner.

        • 1. Re: Newbie Seam DataModel cannot be cast to ArrayList
          shavo26

          Hi Doug,
          You seemed to be confused from displaying your output either as a drop down combo box(h:selectOneMenu) or as a table(h:dataTable).


          To see an example of drop down combobox go to:
          SelectOneMenuLink.


          See below for data table example:


          Action class:



          @DataModel private List<Attachment> attachments;
          
              @org.jboss.seam.annotations.datamodel.DataModelSelection 
              @Out(required = false)
              private Attachment attachment;
               
               
          /**
               * Get list of attachments and outject to conversation scope    
               */
              @SuppressWarnings("unchecked")
              public void getInquiryAttachments(){
                  attachments = entityManager.createNamedQuery("Attachment.findAllbyInquiryId").setParameter("inquiry", newInquiry.getId() ).getResultList();
              }



          View xhtml page:




          <rich:panel>
                  <f:facet name="header">General Inquiry form - List of attachments</f:facet>
                  <div class="section">
                      <h:outputText value="No Attachments Found"
                                 rendered="#{attachments.rowCount==0}"/>
                         <rich:dataTable id="attachments" value="#{attachments}" var="attachment"
                              rendered="#{attachments.rowCount>0}" rowClasses="rvgRowOne,rvgRowTwo">
                              <h:column id="column1">
                                   <f:facet  id="NameFacet" name="header">File name</f:facet>
                                   <h:outputText value="#{attachment.fileName}" />
                              </h:column>
                              <h:column id="column2">
                                   <f:facet id="DescriptionFacet" name="header">Document</f:facet>
                                   #{attachment.description}
                              </h:column>
                              <h:column id="column3">
                                   <f:facet id="SizeFacet" name="header">Size</f:facet>
                                   #{attachment.fileSize}
                              </h:column>
                              <h:column id="column4">
                                   <f:facet id="FileTypeFacet" name="header">FileType</f:facet>
                                   #{attachment.fileContentType}
                              </h:column>
                              <h:column id="column5">
                                   <f:facet id="Action1Facet" name="header"></f:facet>
                                   <h:commandLink id="remove" value="Remove"
                                        action="#{inquiry.remove}" />
                              </h:column>
                              <h:column id="column6">
                                   <f:facet id="Action2Facet" name="header"></f:facet>
                                   <h:commandLink id="view" value="View" action="#{inquiry.sendFile}" />
                              </h:column>
                         </rich:dataTable>
                    </div>
                    </rich:panel>



          There is a good example of this in Dan Allens Seam in Action book.


          Regards,
          Shane.