4 Replies Latest reply on Oct 19, 2011 4:07 AM by sham alla

    Search does not work with EntityQuery class

    Nuwan Gunarathna Newbie
      Hi,
      What I basically did was I ran ./seam generate-entities for existing tables in the database and I gave me handy test application where I can search for database records in list view. It worked fine.
      Then I want to add these working component in my real(another seam project im working). There eveything worked except custom search. Two components I added was EntityQuery class for some paticlar table and its view page. In my real application when i load the page, the page shows all the existing records in the database But when I try to search with some particular field it does not work. But this is worked in test application. Exactly the same code here and there except class names are different(thats is not the problem btw). I have attached those classes so you can understand well what im talking about. Please help me what I have missed in configurations or what ever. Here are the code.

      QUERY CLASS
      ============

      package com.productiongenie.showbitz.model.query;

      import java.util.Arrays;

      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.framework.EntityQuery;

      import com.productiongenie.showbitz.model.PropBrief;

      @Name("propBriefList")
      public class PropBriefListQuery extends EntityQuery<PropBrief> {

         private static final long serialVersionUID = 1L;

         private static final String EJBQL = "select propBrief from PropBrief propBrief";

         private static final String[] RESTRICTIONS = { "lower(propBrief.name) like lower(concat(#{propBriefList.propBrief.name},'%'))", };

         private PropBrief propBrief = new PropBrief();

         public PropBriefListQuery() {
            setEjbql(EJBQL);
            setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
            setMaxResults(25);
         }

         public PropBrief getPropBrief() {
            return propBrief;
         }
      }


      VIEW PAGE
      ==========

      <!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:rich="http://richfaces.org/rich"
         template="layout/template.xhtml">

         <ui:define name="content_body">

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

               <rich:simpleTogglePanel label="PropBrief Search Filter" switchType="ajax">

                    <s:decorate template="layout/display.xhtml">
                     <ui:define name="label">Name</ui:define>
                     <h:inputText id="name" value="#{propBriefList.propBrief.name}" />
                  </s:decorate>


                  <s:decorate template="layout/display.xhtml">
                     <ui:define name="label">Match</ui:define>
                     <h:selectOneRadio id="logic" value="#{propBriefList.restrictionLogicOperator}"
                        styleClass="radio">
                        <f:selectItem itemLabel="All" itemValue="and" />
                        <f:selectItem itemLabel="Any" itemValue="or" />
                     </h:selectOneRadio>
                  </s:decorate>

               </rich:simpleTogglePanel>

               <div class="actionButtons"><h:commandButton id="search" value="Search"
                  action="/production_prop_list.xhtml" /> <s:button id="reset" value="Reset"
                  includePageParams="false" /></div>

            </h:form>

            <rich:panel>
               <f:facet name="header">PropBrief Search Results (#{empty propBriefList.resultList ? 0 : (propBriefList.paginated ? propBriefList.resultCount : propBriefList.resultList.size)})</f:facet>
               <div class="results" id="propBriefList"><h:outputText
                  value="The propBrief search returned no results."
                  rendered="#{empty propBriefList.resultList}" /> <rich:dataTable id="propBriefList"
                  var="_propBrief" value="#{propBriefList.resultList}"
                  rendered="#{not empty propBriefList.resultList}">



                  <h:column>
                     <f:facet name="header">
                        <ui:include src="layout/sort.xhtml">
                           <ui:param name="entityList" value="#{propBriefList}" />
                           <ui:param name="propertyLabel" value="Name" />
                           <ui:param name="propertyPath" value="propBrief.name" />
                        </ui:include>
                     </f:facet>
                     <h:outputText value="#{_propBrief.name}" />
                  </h:column>
                  <h:column>
                     <f:facet name="header">
                        <ui:include src="layout/sort.xhtml">
                           <ui:param name="entityList" value="#{propBriefList}" />
                           <ui:param name="propertyLabel" value="Production id" />
                           <ui:param name="propertyPath" value="propBrief.production.id" />
                        </ui:include>
                     </f:facet>
                     <h:outputText value="#{_propBrief.production.id}" />
                  </h:column>
                  <h:column>
                     <f:facet name="header">
                        <ui:include src="layout/sort.xhtml">
                           <ui:param name="entityList" value="#{propBriefList}" />
                           <ui:param name="propertyLabel" value="Status" />
                           <ui:param name="propertyPath" value="propBrief.status" />
                        </ui:include>
                     </f:facet>
                     <h:outputText value="#{_propBrief.status}" />
                  </h:column>

                  <rich:column styleClass="action">
                     <f:facet name="header">Action</f:facet>
                     <s:link view="/#{empty from ? 'PropBrief' : from}.xhtml"
                        value="#{empty from ? 'View' : 'Select'}"
                        propagation="#{empty from ? 'none' : 'default'}" id="propBriefViewId">
                        <f:param name="propBriefId" value="#{_propBrief.id}" />
                     </s:link>
                  #{' '}
                  <s:link view="/PropBriefEdit.xhtml" value="Edit" propagation="none" id="propBriefEdit"
                        rendered="#{empty from}">
                        <f:param name="propBriefId" value="#{_propBrief.id}" />
                     </s:link>
                  </rich:column>
               </rich:dataTable></div>
            </rich:panel>

            <div class="tableControl"><s:link view="/production_prop_list.xhtml"
               rendered="#{propBriefList.previousExists}"
               value="#{messages.left}#{messages.left} First Page" id="firstPage">
               <f:param name="firstResult" value="0" />
            </s:link> <s:link view="/production_prop_list.xhtml" rendered="#{propBriefList.previousExists}"
               value="#{messages.left} Previous Page" id="previousPage">
               <f:param name="firstResult" value="#{propBriefList.previousFirstResult}" />
            </s:link> <s:link view="/production_prop_list.xhtml" rendered="#{propBriefList.nextExists}"
               value="Next Page #{messages.right}" id="nextPage">
               <f:param name="firstResult" value="#{propBriefList.nextFirstResult}" />
            </s:link> <s:link view="/production_prop_list.xhtml" rendered="#{propBriefList.nextExists}"
               value="Last Page #{messages.right}#{messages.right}" id="lastPage">
               <f:param name="firstResult" value="#{propBriefList.lastFirstResult}" />
            </s:link></div>

            <s:div styleClass="actionButtons" rendered="#{empty from}">
               <s:button view="/PropBriefEdit.xhtml" id="create" propagation="none" value="Create propBrief">
                  <f:param name="propBriefId" />
               </s:button>
            </s:div>

         </ui:define>

      </ui:composition>