2 Replies Latest reply on Dec 13, 2006 9:36 PM by JBoss Fan

    Programatic example for Query Objects

    JBoss Fan Newbie

      Hello,

      Are there any examples showing programmatic use of Query object. Mainly interested seen the capabilites of the "framework:restrictions" piece.

      I've had a quick overview in the code for the Query class but not evident at least for me.

      I found the comparation for Home Object between programmatic and xml aproach very illustrative.

      Thanks for your assistance.

      Yeyo

        • 1. Re: Programatic example for Query Objects
          James Kelly Newbie

          This may not be what you're looking for, but here's a sample where I'm using an EntityQuery to populate an auto-complete list of names (forgive any syntax errors, I cribbed this from my working code, but changed the names.).


          @In(required = false)
          Person examplePerson;
          
          @Out(required = false)
          EntityQuery people;
          
          @Factory("people")
          public void refreshPeople() {
          
           List<String> restrictions = new ArrayList<String>();
           restrictions.add("lower(name) like lower( #{examplePerson.name} || '%' )");
          
           people = new EntityQuery();
           people.setEjbql("from Person");
           people.setOrder("name");
           people.setMaxResults(10);
           people.setRestrictions(restrictions);
          }



          <h:inputText value="#{examplePerson.name}">
           <a4j:support event="onkeyup" reRender="autocompletePeople" action="#{personHome.refreshPeople}" requestDelay="100" />
          </h:inputText>
          
          <a4j:outputPanel id="autocompletePeople">
          <ul>
           <ui:repeat value="#{people.resultList}" var="p">
           <li>
           <h:outputText value="#{p.name}" />
           </li>
           </ui:repeat>
          </ul>
          </a4j:outputPanel>
          




          • 2. Re: Programatic example for Query Objects
            JBoss Fan Newbie

            That's perfect!, it does help me. Thanks
            I was just trying to get my head around the concept but I think I got it.

            BTW, it's extremely exciting to see 1.1.GA !

            Congrats Seam guys!