Custom Search does not work with EntityQuery
nuwanr Aug 17, 2010 1:24 AMHi I am using the following EntityQuery class to do a simple search from a web page(facelets and richfaces).
Problem is when i try to search records for a specific tag it does not work ie. all the records are shown.
I have attached the EntityQuery class and my xhtml page bellow. Please can sombody tell me what will be possible reason for the impediment ?
Entity Class
=================
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;
}
}
Search 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>
Problem is when i try to search records for a specific tag it does not work ie. all the records are shown.
I have attached the EntityQuery class and my xhtml page bellow. Please can sombody tell me what will be possible reason for the impediment ?
Entity Class
=================
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;
}
}
Search 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>