Seam Query Component - pagination mystery
garcimouche Nov 17, 2009 6:20 PM(New to SEAM and RichFaces)
I'd like to have a search capability
on my main form to help the user filling out a specific inputText field.
I decided to implement it with a rich:modalpanel, with the help of some javascript to bring back the desired value to my initial inputtext on the main page.
Inside my modal panel I have a search field and a search result grid (rich:datatable) backed by a SEAM Query Component. I'd like the grid to be paginated.
The problem I face is that the Next-Page, Last-Page links work well, but the previous-page, first-page doesn't do anything. I try to debug, but it seems that the firstResult
variable get never updated when I click previous-page/first-page....The scope of my Query component is the default one (EVENT).
In the Ajax Debug window I can see that the 'firstResult' parameter is passed in the request...
Any pointers would be appreciated.
<rich:modalPanel id="searchCarrier"> <f:facet name="header"> <h:outputText value="Search Carrier"/> </f:facet> <a:form> <rich:panel> <a:region> <h:inputText id="partyName" value="#{pickCarrier.carrierName}" /> <a:commandButton reRender="searchResultPanel" value="Search" action="#{pickCarrier.searchCarrier}"/> </a:region> </rich:panel> <rich:panel id="searchResultPanel"> <f:facet name="header">Carrier Search Results (#{empty pickCarrier.resultList ? 0 : (pickCarrier.paginated ? pickCarrier.resultCount : pickCarrier.resultList.size)})</f:facet> <h:outputText value="The carrier search returned no results." rendered="#{empty pickCarrier.resultList}" /> <rich:dataTable id="partyListGrid" var="_party" value="#{pickCarrier.resultList}" rendered="#{not empty pickCarrier.resultList}"> <h:column> <f:facet name="header">#{title}</f:facet> <a href="#" onclick="var carrierCode = document.getElementById('entry:carrierField:carrierCode');var carrierId = document.getElementById('entry:carrierId');carrierCode.value='#{_party.carrierCode}';carrierId.value='#{_party.id}';carrierCode.focus();Richfaces.hideModalPanel('searchCarrier');"> <h:outputText value="#{_party.name}" /> </a> </h:column> <h:column> <f:facet name="header">#{code}</f:facet> <h:outputText id="toto" value="#{_party.carrierCode}" /> </h:column> </rich:dataTable> </rich:panel> <div class="tableControl"> <a:outputPanel ajaxRendered="true"> <a:commandLink rendered="#{pickCarrier.previousExists}" value="#{messages.left}#{messages.left} First Page" id="firstPage" reRender="searchResultPanel" action="#{pickCarrier.searchCarrier}"> <a:actionparam name="firstResult" value="0" assignTo="#{pickCarrier.firstResult}"/> </a:commandLink> <a:commandLink rendered="#{pickCarrier.previousExists}" value="#{messages.left} Previous Page" id="previousPage" reRender="searchResultPanel" action="#{pickCarrier.searchCarrier}"> <a:actionparam name="firstResult" value="#{pickCarrier.previousFirstResult}" assignTo="#{pickCarrier.firstResult}"/> </a:commandLink> <a:commandLink rendered="#{pickCarrier.nextExists}" value="Next Page #{messages.right}" id="nextPage" reRender="searchResultPanel" action="#{pickCarrier.searchCarrier}"> <a:actionparam name="firstResult" value="#{pickCarrier.nextFirstResult}" assignTo="#{pickCarrier.firstResult}"/> </a:commandLink> <a:commandLink rendered="#{pickCarrier.nextExists}" value="Last Page #{messages.right}#{messages.right}" id="lastPage" reRender="searchResultPanel" action="#{pickCarrier.searchCarrier}"> <a:actionparam name="firstResult" value="#{pickCarrier.lastFirstResult}" assignTo="#{pickCarrier.firstResult}"/> </a:commandLink> </a:outputPanel> </div> </a:form> </rich:modalPanel>
My Seam Component:
@Name("pickCarrier") public class PickCarrierAction extends EntityQuery<Party> { private static final long serialVersionUID = 1L; private static final String EJBQL = "select party from Party party join party.partyRolesForCurrent party_role where party_role.partyTypeByCurrentRole.code = 'CA'"; private static final String RESTRICTION_CARRIER_CODE = "party.carrierCode=#{pickCarrier.carrierCode}"; private static final String RESTRICTION_CARRIER_NAME = "lower(party.name) like lower(concat(#{pickCarrier.carrierName},'%'))"; @In private FacesMessages facesMessages; @In private EntryHome entryHome; private String carrierCode; private String carrierName; public PickCarrierAction() { setEjbql(EJBQL); setMaxResults(1); } public void searchCarrier(){ setRestrictionExpressionStrings(Arrays.asList(RESTRICTION_CARRIER_NAME)); } public void verifyCarrierCodeExists(String widgetId) { try { if(StringUtils.isEmpty(carrierCode)){ facesMessages.addToControl(widgetId, Severity.ERROR, "carrier code is mandatory"); return; } setRestrictionExpressionStrings(Arrays.asList(RESTRICTION_CARRIER_CODE)); Party carrier = this.getSingleResult(); if(entryHome!=null && entryHome.getInstance()!=null) { entryHome.getInstance().setPartyByCarrier(carrier); } } catch(NoResultException nre){ facesMessages.addToControl(widgetId, Severity.ERROR, "carrier code does not exist"); } } public void setCarrierCode(String carrierCode) { this.carrierCode = carrierCode; } public String getCarrierCode() { return carrierCode; } public void setCarrierName(String carrierName) { this.carrierName = carrierName; } public String getCarrierName() { return carrierName; } }