0 Replies Latest reply on Apr 20, 2014 2:20 PM by soniya

    problems creating drop down menu using selectOneMenu

    soniya

      Hello,

      I am new to seam. I've been trying to create a drop down menu in order to choose an entity "tipus" which is a foreign key of another entity "SLA".

      After consulting so many forums and tutorials I've been able to code it but the problem is that I'm not getting any "tipus" to choose from in the dropdown list.

      It just says "Select a Tipus".

      Can anyone please tell me where is the problem.

       

      A part of my SlaEdit.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.org/schema/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:a="http://richfaces.org/a4j"

          xmlns:rich="http://richfaces.org/rich"

          template="layout/template.xhtml">

       

       

      <ui:define name="body">

       

       

          <h:form id="sla" styleClass="edit">

       

               <s:decorate id="tipusField" template="layout/edit.xhtml">

              <ui:define name="label">Tipus: </ui:define>

            

              <h:selectOneMenu value="#{TipusActionBean.selectedTipus}" id="tipus" required="true">

                              <s:selectItems value="#{TipusActionBean.tipusToTrack}"

                                 var="_tipus"

                                 label="#{_tipus.idTipus}"

                                 noSelectionLabel="Select a tipus." />

                                 <s:convertEntity />

                    

                                 <f:ajax event="change" action="#{TipusActionBean.test()}" reRender="tipusField" />

                    

                  </h:selectOneMenu>

                </s:decorate>

       

          </rich:tab>

      </rich:tabPanel>

      </ui:define>

       

       

      </ui:composition>

       

       

       

      My TipusActionBean.java

       

      @Stateful

      @Name("tipusAction")

       

       

      public class TipusActionBean implements tipusAction, Serializable{

        /**

           *

           */

          @In(create = true)

          private TipusList tipuList;

          TipusHome tipusHome;

        

          @PersistenceContext(type = PersistenceContextType.EXTENDED)

          EntityManager entityManager;

        

          @Logger private Log log;

       

       

          @DataModel

          private List<Tipus> tipusToTrack = new ArrayList<Tipus>();

       

       

          @Out(required = false)

          @In(required = false)

          private Tipus selectedTipus = new Tipus();

       

       

          @Factory("tipusToTrack")

          public List<Tipus> initTipusToTrack() {

          tipusToTrack =entityManager.createQuery("select t from Tipus t order by t.idTipus").getResultList();

                System.out.println("initTipusToTrack");

                return tipusToTrack;

          }

       

       

        

          public Tipus getSelectedTipus() {

                  log.info(">>>>> get selectedTipus");

       

       

                  if (this.selectedTipus != null) {

                          log.info(">>>>> get getSelectedProfil selectedTipus = "

                                          + this.selectedTipus.getIdTipus());

                  }

                  return this.selectedTipus;

          }

        

       

       

          public void setSelectedProfil(Tipus tipus) {

                  this.selectedTipus = tipus;

          }

       

       

       

       

          public void test() {

          tipusHome.setTipusIdTipus(selectedTipus.getIdTipus());

                  System.out.println("test");

                  System.out.println(selectedTipus == null ? "null" : selectedTipus.getIdTipus());

          }

       

       

          @Remove

          public void remove() {

          }

      }

       

      And my SlaEdit.page.xml

       

      <?xml version="1.0" encoding="UTF-8"?>

      <page xmlns="http://jboss.org/schema/seam/pages"

            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

            xsi:schemaLocation="http://jboss.org/schema/seam/pages http://jboss.org/schema/seam/pages-2.3.xsd"

            no-conversation-view-id="/SlaList.xhtml"

            login-required="true">

       

       

         <begin-conversation join="true" flush-mode="MANUAL"/>

       

       

         <action execute="#{slaHome.wire}"/>

       

         <param name="slaFrom"/>

         <param name="slaIdSla" value="#{slaHome.slaIdSla}"/>

         <param name="tipusFrom"/>

         <param name="tipusIdTipus" value="#{tipusHome.tipusIdTipus}"/>

       

         <navigation from-action="#{slaHome.persist}">

            <rule if-outcome="persisted">

               <end-conversation/>

               <redirect view-id="/Sla.xhtml"/>

            </rule>

         </navigation>

       

       

         <navigation from-action="#{slaHome.update}">

            <rule if-outcome="updated">

               <end-conversation/>

               <redirect view-id="/Sla.xhtml"/>

            </rule>

         </navigation>

       

       

         <navigation from-action="#{slaHome.remove}">

            <rule if-outcome="removed">

               <end-conversation/>

               <redirect view-id="/SlaList.xhtml"/>

            </rule>

         </navigation>

       

      </page>

       

      Please, can anyone tell me if there is something wrong in the code of any other changes i need to make?

      Thanks in advance.