Pass list as page parameter
matt.hibb Nov 3, 2010 7:27 PMI have started an application from seam-gen and I am wanting to add to the default search functionality.
The search criteria for the email, id etc fields works fine, as does the pagination. However I am stuck trying to add the search capability on the keyword field. The problem being that the value is not binding to the keywords list in the restrictionLogEvent. This is because I don't know how to pass this param like the others using a param definition in the page xml like the other fields.
Is this even possible?
If not, can anyone suggest a better way of implementing the search?
Thanks!
List 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" xmlns:a4j="http://richfaces.org/a4j" template="/layout/template.xhtml"> <ui:define name="body"> <h:form id="logEventSearch" styleClass="edit"> <rich:simpleTogglePanel label="LogEvent Search Filter" switchType="ajax"> <s:decorate template="/layout/display.xhtml"> <ui:define name="label">Id</ui:define> <h:inputText id="id" value="#{logEventList.restrictionLogEvent.id}"/> </s:decorate> <s:decorate template="/layout/display.xhtml"> <ui:define name="label">Email</ui:define> <h:inputText id="email" value="#{logEventList.restrictionLogEvent.email}"/> </s:decorate> <s:decorate template="/layout/display.xhtml"> <ui:define name="label">User Comments</ui:define> <h:inputText id="emailbody" value="#{logEventList.restrictionLogEvent.emailbody}"/> </s:decorate> <s:decorate template="/layout/display.xhtml"> <ui:define name="label">Log Type</ui:define> <h:inputText id="logtype" value="#{logEventList.restrictionLogEvent.logtype}"/> </s:decorate> <s:decorate template="/layout/display.xhtml"> <ui:define name="label">Title</ui:define> <h:inputText id="title" value="#{logEventList.restrictionLogEvent.title}"/> </s:decorate> <s:decorate template="/layout/display.xhtml"> <ui:define name="label">Version</ui:define> <h:inputText id="version" value="#{logEventList.restrictionLogEvent.version}"/> </s:decorate> <s:decorate template="/layout/display.xhtml"> <ui:define name="label">Keywords</ui:define> <rich:pickList value="#{logEventList.restrictionLogEvent.keywords}"> <s:selectItems value="#{keywordList.resultList}" var="keyword" label="#{keyword.name}" /> <s:convertEntity /> </rich:pickList> </s:decorate> <s:decorate template="/layout/display.xhtml"> <ui:define name="label">Match</ui:define> <h:selectOneRadio id="logic" value="#{logEventList.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="/secure/LogEventList.xhtml"/> <s:button id="reset" value="Reset" includePageParams="false"/> </div> </h:form> <a4j:region> <h:form> <a4j:poll id="poll" interval="20000" reRender="logEventList" enabled="#{pollStatus.pollEnabled}" /> </h:form> </a4j:region> <h:form> <rich:panel id="logEventListPanel"> <f:facet name="header">LogEvent Search Results (#{empty logEventList.resultList ? 0 : (logEventList.paginated ? logEventList.resultCount : logEventList.resultList.size)})</f:facet> <div class="results" id="logEventList"> <a4j:commandButton style="width:120px" id="control" value="#{pollStatus.pollEnabled?'Stop':'Start'} Auto Refresh" reRender="poll, logEventListPanel"> <a4j:actionparam name="polling" value="#{!pollStatus.pollEnabled}" assignTo="#{pollStatus.pollEnabled}" /> </a4j:commandButton> <rich:dataTable id="logEventList" var="logEvent" value="#{logEventList.resultList}" rendered="#{not empty logEventList.resultList}"> <h:column> <f:facet name="header"> <ui:include src="/layout/sort.xhtml"> <ui:param name="entityList" value="#{logEventList}"/> <ui:param name="propertyLabel" value="Id"/> <ui:param name="propertyPath" value="logEvent.id"/> </ui:include> </f:facet> <s:link view="/secure/logEventEdit.xhtml" value="#{logEvent.id}"> <f:param name="logEventId" value="#{logEvent.id}" /> </s:link> </h:column> <h:column> <f:facet name="header"> <ui:include src="/layout/sort.xhtml"> <ui:param name="entityList" value="#{logEventList}"/> <ui:param name="propertyLabel" value="Version"/> <ui:param name="propertyPath" value="logEvent.version"/> </ui:include> </f:facet> <h:outputText value="#{logEvent.version}"/> </h:column> <h:column> <f:facet name="header"> <ui:include src="/layout/sort.xhtml"> <ui:param name="entityList" value="#{logEventList}"/> <ui:param name="propertyLabel" value="Created"/> <ui:param name="propertyPath" value="logEvent.created"/> </ui:include> </f:facet> <h:outputText value="#{logEvent.created}"> <s:convertDateTime type="both" dateStyle="short"/> </h:outputText> </h:column> <h:column> <f:facet name="header"> <ui:include src="/layout/sort.xhtml"> <ui:param name="entityList" value="#{logEventList}"/> <ui:param name="propertyLabel" value="Email"/> <ui:param name="propertyPath" value="logEvent.email"/> </ui:include> </f:facet> <h:outputText value="#{logEvent.email}"/> </h:column> <h:column> <f:facet name="header"> <ui:include src="/layout/sort.xhtml"> <ui:param name="entityList" value="#{logEventList}"/> <ui:param name="propertyLabel" value="User Comments"/> <ui:param name="propertyPath" value="logEvent.emailbody"/> </ui:include> </f:facet> <s:formattedText value="#{logEvent.emailbody}"/> </h:column> <h:column> <f:facet name="header"> <ui:include src="/layout/sort.xhtml"> <ui:param name="entityList" value="#{logEventList}"/> <ui:param name="propertyLabel" value="Key Id"/> <ui:param name="propertyPath" value="logEvent.keyId"/> </ui:include> </f:facet> <h:outputText value="#{logEvent.keyId}"/> </h:column> <h:column> <f:facet name="header"> <ui:include src="/layout/sort.xhtml"> <ui:param name="entityList" value="#{logEventList}"/> <ui:param name="propertyLabel" value="Log Type"/> <ui:param name="propertyPath" value="logEvent.logtype"/> </ui:include> </f:facet> <h:outputText value="#{logEvent.logtype}"/> </h:column> <h:column> <f:facet name="header"> <ui:include src="/layout/sort.xhtml"> <ui:param name="entityList" value="#{logEventList}"/> <ui:param name="propertyLabel" value="Message"/> <ui:param name="propertyPath" value="logEvent.message"/> </ui:include> </f:facet> <a4j:htmlCommandLink value="#{logEvent.message}" action="#{logDownloader.download}"> <f:param name="logEventId" value="#{logEvent.id}" /> </a4j:htmlCommandLink> </h:column> <h:column> <f:facet name="header"> <ui:include src="/layout/sort.xhtml"> <ui:param name="entityList" value="#{logEventList}"/> <ui:param name="propertyLabel" value="Title"/> <ui:param name="propertyPath" value="logEvent.title"/> </ui:include> </f:facet> <h:outputText value="#{logEvent.title}" /> </h:column> <rich:column styleClass="action"> <f:facet name="header">Keywords</f:facet> <a4j:repeat var="keyword" value="#{logEvent.keywords}" rowKeyVar="count"> <h:outputText value=", " rendered="#{count > 0}" /> <h:outputText value="#{keyword.name}" title="#{keyword.description}" /> </a4j:repeat> </rich:column> <rich:column styleClass="action"> <f:facet name="header">Opportunities</f:facet> <a4j:repeat var="opportunity" value="#{logEvent.opportunities}"> <h:outputText value="#{opportunity.name}" title="#{opportunity.description}" /> </a4j:repeat> </rich:column> </rich:dataTable> </div> </rich:panel> </h:form> <div class="tableControl"> <s:link view="/secure/LogEventList.xhtml" rendered="#{logEventList.previousExists}" value="#{messages.left}#{messages.left} First Page" id="firstPage"> <f:param name="firstResult" value="0"/> </s:link> <s:link view="/secure/LogEventList.xhtml" rendered="#{logEventList.previousExists}" value="#{messages.left} Previous Page" id="previousPage"> <f:param name="firstResult" value="#{logEventList.previousFirstResult}"/> </s:link> <s:link view="/secure/LogEventList.xhtml" rendered="#{logEventList.nextExists}" value="Next Page #{messages.right}" id="nextPage"> <f:param name="firstResult" value="#{logEventList.nextFirstResult}"/> </s:link> <s:link view="/secure/LogEventList.xhtml" rendered="#{logEventList.nextExists}" value="Last Page #{messages.right}#{messages.right}" id="lastPage"> <f:param name="firstResult" value="#{logEventList.lastFirstResult}"/> </s:link> </div> </ui:define> </ui:composition>
List page xml:
<?xml version="1.0" encoding="UTF-8"?> <page xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd"> <param name="firstResult" value="#{logEventList.firstResult}"/> <param name="sort" value="#{logEventList.orderColumn}"/> <param name="dir" value="#{logEventList.orderDirection}"/> <param name="logic" value="#{logEventList.restrictionLogicOperator}"/> <param name="from"/> <param name="id" value="#{logEventList.restrictionLogEvent.id}"/> <param name="build" value="#{logEventList.restrictionLogEvent.build}"/> <param name="email" value="#{logEventList.restrictionLogEvent.email}"/> <param name="emailbody" value="#{logEventList.restrictionLogEvent.emailbody}"/> <param name="logtype" value="#{logEventList.restrictionLogEvent.logtype}"/> <param name="message" value="#{logEventList.restrictionLogEvent.message}"/> <param name="requiresupport" value="#{logEventList.restrictionLogEvent.requiresupport}"/> <param name="title" value="#{logEventList.restrictionLogEvent.title}"/> <param name="token" value="#{logEventList.restrictionLogEvent.token}"/> <param name="version" value="#{logEventList.restrictionLogEvent.version}"/> </page>
List EntityQuery:
@Name("logEventList") public class LogEventList extends EntityQuery<LogEvent> { private static final long serialVersionUID = -948846997295581654L; private static final String EJBQL = "select logEvent from LogEvent logEvent left join logEvent.keywords keyword"; private static final String[] RESTRICTIONS = { "logEvent.id = #{logEventList.restrictionLogEvent.id}", "lower(logEvent.build) like lower(concat(#{logEventList.restrictionLogEvent.build},'%'))", "lower(logEvent.email) like lower(concat(#{logEventList.restrictionLogEvent.email},'%'))", "lower(logEvent.emailbody) like lower(concat(#{logEventList.restrictionLogEvent.emailbody},'%'))", "lower(logEvent.logtype) like lower(concat(#{logEventList.restrictionLogEvent.logtype},'%'))", "lower(logEvent.message) like lower(concat(#{logEventList.restrictionLogEvent.message},'%'))", "lower(logEvent.requiresupport) like lower(concat(#{logEventList.restrictionLogEvent.requiresupport},'%'))", "lower(logEvent.title) like lower(concat(#{logEventList.restrictionLogEvent.title},'%'))", "lower(logEvent.token) like lower(concat(#{logEventList.restrictionLogEvent.token},'%'))", "lower(logEvent.version) like lower(concat(#{logEventList.restrictionLogEvent.version},'%'))", "keyword.id in (#{not empty logEventList.restrictionLogEvent.keywords ? logEventList.restrictionLogEvent.keywords : null }",}; private LogEvent restrictionLogEvent = new LogEvent(); // Used in above hql for query restrictions public LogEventList() { setEjbql(EJBQL); setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS)); setMaxResults(25); setOrder("created desc"); } public LogEvent getRestrictionLogEvent() { return restrictionLogEvent; } }