2 Replies Latest reply on Sep 24, 2010 6:17 AM by harisjan

    Dynamic DataTable and selectOneMenu

    gribeiro

      Hi, everyone !


      I´ve just started studying Seam abouth a month ago and there are so many doubts in my mind ...
      Well,I´m trying to select an item on a combo and using ajax to render a datatable with object attribute´s value.
      So, here below some code snippets to clarify the situation:


      Managed Bean


      @Name("funcionarioBean")
      @Scope(ScopeType.CONVERSATION)
      public class FuncionarioBeanImpl extends
                GenericCrudBackingBeanImpl<Funcionario> implements FuncionarioBean {
           
      
           @In(create = true)
           private FuncionarioBusiness funcionarioBusiness;
      
           @In(create = true)
           private CargoBusiness cargoBusiness;
      
           @DataModel(value = "funcionarios")
           private List<Funcionario> funcionarios;
      
           // @DataModelSelection(value = "funcionarios")
           @Out(required = false)
           private Funcionario funcionario;
           
           @DataModel
           private List<Cargo> cargosselec;
      
      
           @DataModelSelection(value = "listaDeCargos")
           // @Out(required = false)
           private Cargo cargoselec;
      
           @DataModel
           private List<Cargo> listaDeCargos;
      
           @Factory(value = "listaDeCargos")
           public List<Cargo> getLista() {
      
                return this.listaDeCargos = cargoBusiness.listarTodos();
      
           }
      
           @Begin(nested = true)
           public void processMyValueChange(ValueChangeEvent vce){
                //FIXME Descobrir porque o cargosselec está sendo instanciado toda vez que chamo este método !!!
                  cargoselec = (Cargo) vce.getNewValue(); 
                  //setSongDetail((Cargo)detail.get(cargoselec));
                  //System.out.println("Cargo Selecionado :"+cargoselec.getDescricao());
                  
                  if (cargosselec==null) {
                       cargosselec = new ArrayList<Cargo>();
                       cargosselec.add(cargoselec);
                        System.out.println("Cargo adicionado =>"+ "Código :"+cargoselec.getId()+ "Descrição :"+cargoselec.getDescricao());
                        System.out.println("Tamanho da lista de cargos selecionados :"+cargosselec.size());
                     
                  } else {
                       cargosselec.add(cargoselec);
                        System.out.println("Cargo adicionado =>"+ "Código :"+cargoselec.getId()+ "Descrição :"+cargoselec.getDescricao());
                        System.out.println("Tamanho da lista de cargos selecionados :"+cargosselec.size());
                  
                  }
                       
                              
           }
      



      XHTML PAGE


                     <s:decorate id="comboCargos">
                          <ui:define name="label">
                               <h:outputLabel value="Cargos" />
                          </ui:define>
      
                          <h:selectOneMenu value="#{cargoselec}" valueChangeListener="#{funcionarioBean.processMyValueChange}" >
                                                   
                               <s:selectItems value="#{listaDeCargos}" var="cargos" 
                                    label="#{cargos.descricao}" hideNoSelectionLabel="true"
                                    noSelectionLabel=" Selecione..." />
                                    
                                    <a:support event="onchange" reRender="tabelaCargos" onsubmit="if(!confirm('Confirma o cargo selecionado ?')) {form.reset(); return false;}"/>
      
                               <s:convertEntity />
      
                          </h:selectOneMenu>
                     </s:decorate>
      
      
      <ui:define name="tituloDatagrid">
                <h:outputLabel value="Dados Profissionais" />
           </ui:define>
      
           <ui:define name="tabelaDataGrid">
                <h:dataTable id="tabelaCargos" value="#{cargosselec}" var="crgsel"
                     rendered="#{cargosselec.size > 0}">
                     <h:column>
                          <f:facet name="header">
                               <h:outputLabel value="Codigo" />
                          </f:facet>
                          <h:outputText value="#{crgsel.id}" />
                     </h:column>
                     <h:column>
                          <f:facet name="header">
                               <h:outputLabel value="Descricao" />
                          </f:facet>
                          <s:link value="#{crgsel.descricao}"
                               action="#{funcionarioBean.editar(funcionario)}" />
                     </h:column>
                     <h:column>
                          <f:facet name="header">
                               <h:outputLabel value="Acao" />
                          </f:facet>
                          <h:commandLink action="#{cargoBean.deletar(cargo)}"
                               onclick="return confirmDelete()">
                               <h:graphicImage value="/_images/false.png" style="border: none" />
                               <a:support event="oncomplete" reRender="tabelaCargos" />
                          </h:commandLink>
                     </h:column>
                </h:dataTable>
           </ui:define>
      
      



      At this pont I can add to cargosselect attribute each selected item from my combobox, but It´s not start rendering the datatable as expected.


      Please, if anyone could help me out on this I´d be very grateful.


      Gribeiro




        • 1. Re: Dynamic DataTable and selectOneMenu
          nickarls

          Please post this one forum up (Seam Users)

          • 2. Re: Dynamic DataTable and selectOneMenu
            harisjan

            i have the exact same problem the drop down isn't passing the value to the bean variable which will carry the value and put it in an HQL query which is supposed to populate the data table
            but the value selected in the selected items is not being passed to the select one menu value which is the bean variable and i dont know why here is the


            JSP code :



            <s:decorate id="serTaskIdField"  template="layout/display.xhtml">
                            <ui:define name="label">Tasks</ui:define>
                            <h:selectOneMenu id="serTaskId"
                            value="#{taskUpdate.name}">
                                <s:selectItems  value="#{tblTaskList.resultList}" var="_b" label="#{_b.txtName}" itemValue="helllo">  </s:selectItems>               
                                 <a:support event="onblur" reRender="serTaskIdField" bypassUpdates="true" ajaxSingle="true"/>
                                 <s:convertEntity/>
                                  </h:selectOneMenu>
                                </s:decorate>



            HERE IS THE BACKING BEAN



            package org.domain.taskmanager1.session;
            
            import java.util.List;
            
            import javax.ejb.Remove;
            
            import javax.ejb.Stateless;
            import javax.persistence.EntityManager;
            
            import org.jboss.seam.annotations.Factory;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Logger;
            import org.jboss.seam.annotations.datamodel.DataModel;
            import org.jboss.seam.log.Log;
            import org.jboss.seam.security.Credentials;
            import org.jboss.seam.international.StatusMessages;
            import org.domain.taskmanager1.entity.TblTask;
            import org.hibernate.validator.Length;
            
            @Stateless
            @Name("taskUpdate")
            public class TaskUpdateBean implements TaskUpdate
            {
                 
                 int task_Id;
                 private String name;
            
                 
                  
                  public String getName() {
                       System.out.print("the value of the name getter="+name);
                      return name;
                 }
            
            
            
                 public void setName(String name) {
                      this.name = name;
                      System.out.print("the value of the name setter="+name);
                 }
            
            
            
                 public int getTask_Id() {
                       System.out.print("the value of the taskId getter="+task_Id);
                      return task_Id;
                      
                 }
            
            
            
                 public void setTask_Id(int taskId) {
                      task_Id = taskId;
                      System.out.print("the value of the taskId setter="+task_Id);
                 }
            
                 @Logger private Log log;
                  @In EntityManager entityManager;
                  @In StatusMessages statusMessages;
                  @In Credentials credentials;
                  
                  
                  @DataModel
                  private List<TblTask> subtask;
                  
                  @DataModel
                  private List<TblTask> predessor ;
                  
                  @DataModel
                  private List<TblTask> comments;
                  
                  public void taskUpdate()
                  {
                   // implement your business logic here
                   log.info("taskUpdateQueries.taskUpdateQueries() action called");
                   statusMessages.add("taskUpdateQueries");
               }
               
               
            
                 @SuppressWarnings("unchecked")
                 @Factory("predessor")
                 public  void RelatedPredessors()
               { 
                      
                      predessor= entityManager.createQuery("SELECT DISTINCT t  FROM TblTask t RIGHT JOIN t.predessors pre LEFT JOIN t.taskStatus ts  where pre.numSubTaskId= :taskId")
                       .setParameter("taskId", 3)
                       .getResultList();
                      
            System.out.print("the value of the taskId="+task_Id);
            System.out.print("the value of the name="+name);
            }
                 
                 @SuppressWarnings("unchecked")
                 @Factory("subtask")
                 public  void RelatedSubtasks()
               {
                      
                      subtask= entityManager.createQuery("SELECT DISTINCT t  FROM TblTask t RIGHT JOIN t.subtasks sub LEFT JOIN t.taskStatus ts where sub.numPredecessorTask= :taskId")
                       .setParameter("taskId", 3)
                       .getResultList();
                      }
                 
                 @SuppressWarnings("unchecked")
                 @Factory("comments")
                 public  void RelatedComments()
               {
                      comments= entityManager.createQuery("SELECT DISTINCT t  FROM TblTask t LEFT JOIN t.comments comm where t.serTaskId= :taskId")
                       .setParameter("taskId", 3)
                       .getResultList();
                      }
            
            
                 
            }