2 Replies Latest reply on Aug 6, 2009 11:18 AM by lvdberg

    extra queries from s:selectItems and s:convertEntity?

    jfaath

      Hello, I'm new to Seam so learning as I'm going.  By following examples (mainly, the UI selectItems example), I've gotten these components to work just fine, but I was curious as to what is happening behind the scenes since extra queries are being called.  I simply have several select boxes similar to this:


      <div class="entry">
        <div class="label"><h:outputLabel for="country">Country:</h:outputLabel></div>
        <div class="input">
          <s:decorate>
            <h:selectOneMenu id="country" value="#{item.country}">
              <s:selectItems var="country" value="#{countries.resultList}" label="#{country.country}" noSelectionLabel="Please select..."></s:selectItems>
              <s:convertEntity />
            </h:selectOneMenu>
          </s:decorate>
        </div>
      </div>
      



      Looking at the generated HTML, it looks like a new Id value is created for each item.  That's fine, since it works OK, but what is odd is that if I set the field, whenever I move around to other fields, two select queries are being called.  One is essentially returning all the countries, and another is returning a country for a given Id (viewing the Hibernate output).


      I have 4 similar select boxes on this form, so if I've used all of them, when I'm moving to other fields, 8 queries are being called.  This seems unnecessary...perhaps I'm doing something wrong?  I've followed the examples to a tee.  Hopefully someone can enlighten me?


      Regards,


      JF


        • 1. Re: extra queries from s:selectItems and s:convertEntity?
          ckarthi

          Though this post is old, even now in the latest Seam release the additional queries are fired.. any links related to this?

          • 2. Re: extra queries from s:selectItems and s:convertEntity?
            lvdberg

            Look at the mapping of your entities and the scope of your beans. You're not using ajax, so this happens when you submit something. If you want to prevent this, you could define a session scoped bean with a factory which provides you with a list of countries whenever you need it. You could make it even nicer by adding an observer which fires a refresh query whenever you change some country entity.


            Details and details are perfectly explained in Seam in Action from Manning.