4 Replies Latest reply on Oct 31, 2012 6:05 AM by luanfg

    @DataModelSelection always empty

    luanfg

      Hello,

       

      I'm having some troubles trying to fill a @DataModelSelection.

      My @DataModel works, the h:dataTable iterates fine, but when I choose a row it just reloads the page, but my selection continues empty.

      I'll post my code above, please, any help will be very welcome.

       

      Bean:

       

      @Name("collaboration")
      
      
      public class CollaborationHome 
      {
                @In
          EntityManager entityManager;
      
      
                @Out(required = false, value="ontologies")
                List<Ontology> oL;
      
      
                @Factory("ontologies")
                public void getOntologies()
                {
                          oL =  (List<Ontology>) entityManager.createQuery("from Ontology").getResultList();
                }
      
      
                private Ontology ontology;
        
                public Ontology getOntology()
                {
                          return ontology;
                }
        
                public void setOntology(Ontology ontology)
                {
                          this.ontology = ontology;
                }
        
                @DataModel
                private List<Universal> universals;
        
                @DataModelSelection("universals")
                @Out(required=false)
                private Universal selectedUniversal;
        
                public void getSelectedUniversal(Universal selectedUniversal)
                {
                          this.selectedUniversal = selectedUniversal;
                }
        
                public Universal getSelectedUniversal()
                {
                          return selectedUniversal;
                }
        
                @Factory("universals")
                public void selectUniversals()
                {
                          {
                                    universals = (List<Universal>)entityManager.createQuery("from Universal where unty_id=1 and onto_id = :ontoid").
                                                                                                               setParameter("ontoid", ontology.getOntoId()).
                                                                                                               getResultList();
                          }
                }
      
          }
      
      

       

      View:

       

      <!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="http://richfaces.org/a4j"
                xmlns:rich="http://richfaces.org/rich" template="layout/template.xhtml">
      
      
                <ui:define name="body">
                          <div>
                                    <h:form>
                                              <rich:panel style="float:left; width:20%">
                                                        <f:facet name="header">Arvore de Conceitos:</f:facet>
                                                        <h:outputLabel value="Ontologia:" ></h:outputLabel>
                                                        <h:selectOneMenu id="cbOntology" value="#{collaboration.ontology}">
                                                                  <s:selectItems value="#{ontologies}" var="onto" label="#{onto.ontoName}" noSelectionLabel="Selecione uma ontologia"/>
                                                                  <s:convertEntity />
                                                        </h:selectOneMenu>
                                                        <h:commandButton id="btnLoadOntology" value="Carregar" action="submit()" />
                                                        <rich:panel rendered="#{not empty collaboration.ontology}" >
                                                                  <h:dataTable value="#{universals}" var="univ">
                                                                            <h:column>
                                                                                      <h:commandLink value="#{univ.univLabelpt}" />
                                                                            </h:column>
                                                                  </h:dataTable>
                                                        </rich:panel>
                                              </rich:panel>
                                              <rich:panel rendered="#{not empty selectedUniversal}">
                                                        <h:outputLabel value="a a #{selectedUniversal}"  />
                                              </rich:panel>
                                    </h:form>
      
      
                          </div>
                </ui:define>
      
      
      </ui:composition>
      
      

       

      As I said, the drop down menu is populated, the load button works fine, then the universal query work aswell, but when I select a universal using the commandLink nothing happens, the page reloads but selectedUniversal still empty.

      I've tried the s:link also, but when the page reloads ontologies becomes null and then I get an error.

      I have no idea what to do, followed every step of the book but still doesn't work =\

        • 1. Re: @DataModelSelection always empty
          luanfg

          No progress yet.

          Now I tried:

           

           

          
          <s:link view="/Collaboration.xhtml" value="#{univ.univLabelpt}">
          
          
          
          
            <f:param name="selectedConc"         
          value="#{collaboration.selectedUniversal}"/>
          
          
          
          
          
          </s:link>
          
          
          

           

          Now when page realods the selectedUniversal object is filled by the one I've selected from the table, but collaboration.ontology is null.

           

          Please, any advice will be very welcone

          • 2. Re: @DataModelSelection always empty
            luanfg

            Still stuck at the same point after a week. Maybe isn't a good idea use DataModel, any tips the way I should do it?

            • 3. Re: @DataModelSelection always empty
              mkouba

              Actually I've never used the @DataModel annotation though here are my observations. CollaborationHome component is bound to the event context so it's created for each Servlet/JSF request and destroyed after the request completes. That might cause the problems. I would try conversation scoped component or Seam extended EL (#{collaboration.selectUniversal(univ)} plus add corresponding selectUniversal() method).

               

              Also I'm not completely sure I understand the business logic but I suppose you want to filter out unviersals for selected ontology (commandButton) and show the detail of selected universal (link in dataTable). Correct me if I'm wrong...

              1 of 1 people found this helpful
              • 4. Re: @DataModelSelection always empty
                luanfg

                You're corret, I want to show details of selected universal.

                 

                Not sure if I understood the problem that you pointed. Also, if I try to change CollaborationHome to @Scope(ScopeType.Conversation) the selectOneMenu stops working. It just doesn't select an ontology, problem that doesn't happen when I use the default scope.

                 

                How would you do to show that information if not using @DataModel Martin?

                 

                Thanks for the answer!