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

    Dynamic DataTable and selectOneMenu

    Geovanny Ribeiro Newbie

      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

      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;
           private List<Cargo> cargosselec;
           @DataModelSelection(value = "listaDeCargos")
           // @Out(required = false)
           private Cargo cargoselec;
           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(); 
                  //System.out.println("Cargo Selecionado :"+cargoselec.getDescricao());
                  if (cargosselec==null) {
                       cargosselec = new ArrayList<Cargo>();
                        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 {
                        System.out.println("Cargo adicionado =>"+ "Código :"+cargoselec.getId()+ "Descrição :"+cargoselec.getDescricao());
                        System.out.println("Tamanho da lista de cargos selecionados :"+cargosselec.size());


                     <s:decorate id="comboCargos">
                          <ui:define name="label">
                               <h:outputLabel value="Cargos" />
                          <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 />
      <ui:define name="tituloDatagrid">
                <h:outputLabel value="Dados Profissionais" />
           <ui:define name="tabelaDataGrid">
                <h:dataTable id="tabelaCargos" value="#{cargosselec}" var="crgsel"
                     rendered="#{cargosselec.size > 0}">
                          <f:facet name="header">
                               <h:outputLabel value="Codigo" />
                          <h:outputText value="#{crgsel.id}" />
                          <f:facet name="header">
                               <h:outputLabel value="Descricao" />
                          <s:link value="#{crgsel.descricao}"
                               action="#{funcionarioBean.editar(funcionario)}" />
                          <f:facet name="header">
                               <h:outputLabel value="Acao" />
                          <h:commandLink action="#{cargoBean.deletar(cargo)}"
                               onclick="return confirmDelete()">
                               <h:graphicImage value="/_images/false.png" style="border: none" />
                               <a:support event="oncomplete" reRender="tabelaCargos" />

      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.


        • 1. Re: Dynamic DataTable and selectOneMenu
          Nicklas Karlsson Master

          Please post this one forum up (Seam Users)

          • 2. Re: Dynamic DataTable and selectOneMenu
            Haris Jan Newbie

            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"
                                <s:selectItems  value="#{tblTaskList.resultList}" var="_b" label="#{_b.txtName}" itemValue="helllo">  </s:selectItems>               
                                 <a:support event="onblur" reRender="serTaskIdField" bypassUpdates="true" ajaxSingle="true"/>


            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;
            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;
                  private List<TblTask> subtask;
                  private List<TblTask> predessor ;
                  private List<TblTask> comments;
                  public void taskUpdate()
                   // implement your business logic here
                   log.info("taskUpdateQueries.taskUpdateQueries() action called");
                 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)
            System.out.print("the value of the taskId="+task_Id);
            System.out.print("the value of the name="+name);
                 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)
                 public  void RelatedComments()
                      comments= entityManager.createQuery("SELECT DISTINCT t  FROM TblTask t LEFT JOIN t.comments comm where t.serTaskId= :taskId")
                       .setParameter("taskId", 3)