Problem with EVENT Scope
ali1983 Jun 16, 2008 2:09 PMHello every one I am having a problem with Event
scope of my class.
Below is my class.
package com.pcounts.server.action.sp; import java.util.List; import java.util.Set; import java.util.Vector; import javax.ejb.Remove; import javax.ejb.Stateful; import javax.ejb.Stateless; import javax.faces.component.UIData; import javax.interceptor.Interceptors; import org.hibernate.type.TrueFalseType; import org.jboss.seam.annotations.Begin; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.End; import org.jboss.seam.annotations.Factory; import org.jboss.seam.annotations.FlushModeType; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Out; import org.jboss.seam.annotations.Scope; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.datamodel.DataModel; import org.richfaces.component.UIDatascroller; import com.pcounts.server.action.auth.PCUserSession; import com.pcounts.server.hibernate.pojo.Contacts; import com.pcounts.server.hibernate.service.ContactService; import com.pcounts.server.hibernate.service.GroupService; import com.pcounts.server.hibernate.service.UserService; @Name("spContactsAction") @Scope(ScopeType.EVENT) public class SPContactsActionBean { @DataModel private List<Contacts> listContacts = null; @In(create = true) ContactService contactService; @In(create = true) GroupService groupService; @In(create = true) PCUserSession pcUserSession; @In(create = true) UserService userService; UIData dataTable; UIDatascroller dataScroller; @SuppressWarnings("unchecked") @Factory(value = "listContacts") public void listContacts() { System.out.println("dataScroller.getPage(): " + dataScroller.getPage()); System.out.println("public void listContacts() called ...."); List listSubSetRecords; List lstGroups; Set setSPsOfGroups; int pageFirstIndex; Long count; lstGroups = groupService.getGroupsForSP(pcUserSession.getUserNumber()); setSPsOfGroups = userService.getSPsFromSalesGroups(lstGroups); count = contactService.getContactsRowCount(userService .getCSVUserNumber(setSPsOfGroups)); System.out.println("Count Value " + count); java.util.Vector vector = new Vector(); vector.setSize(count.intValue()); System.out.println("Vector.size()" + vector.size()); pageFirstIndex = (dataScroller.getPage() * dataScroller.getDataTable() .getRows()) - dataScroller.getDataTable().getRows(); listContacts = contactService.getContacts(userService .getCSVUserNumber(setSPsOfGroups), null, false, pageFirstIndex); System.out.println("listContacts.size() " + listContacts.size()); for (int index = 0; index < listContacts.size(); index++) { vector.set(pageFirstIndex + index, listContacts.get(index)); } for (int i = 0; i < vector.size(); i++) { System.out.println("Vector index " + i + " ) " + vector.get(i)); } listContacts = vector; } public List<Contacts> getListContacts() { return listContacts; } public void setListContacts(List<Contacts> listContacts) { this.listContacts = listContacts; } public UIDatascroller getDataScroller() { return dataScroller; } public void setDataScroller(UIDatascroller dataScroller) { this.dataScroller = dataScroller; } @Remove @Destroy public void destroy(){ } }
And this is contactDetail.xhtml
<!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:a="http://richfaces.org/a4j" template="layout/sp-template.xhtml"> <ui:define name="body"> <table width="98%" cellpadding="0" align="center" cellspacing="0"> <tr> <td align="left"> <table width="152px" align="left" cellpadding="0" cellspacing="0"> <tr> <td class="tabLOnEnd"></td> <td class="tabTxtOnEnd">My Contacts</td> <td class="tabNone"></td> </tr> </table> </td> </tr> <tr> <td colspan="4" width="100%"> <div class="tab-box" style="margin-left:0"> <div class="buttons" style="margin-top:97px; margin-right:9px"><h:commandLink> <h:graphicImage value="../common/image/btn-addnew.gif" /> </h:commandLink></div> <rich:dataTable id="sp-contacts" value="#{listContacts}" cellpadding="0" cellspacing="0" var="contacts" headerClass="tableHeader" rows="15" columnClasses="tableRows" width="100%" columnsWidth="0*"> <rich:column> <f:facet name="header"> <h:outputText value="Edit" /> </f:facet> <a:commandLink action="#{SalesPersonContacts.editAction}"> <h:graphicImage value="../common/image/icon-edit.gif"></h:graphicImage> </a:commandLink> </rich:column> <rich:column> <f:facet name="header"> <a:commandLink action="#{SalesPersonContacts.sortAction('lastName')}" reRender="contactsScroller,sp-contacts" style="text-decoration: none;" value="Last Name"> <h:graphicImage value="../common/image/icon-edit.gif" style="text-decoration: none;"></h:graphicImage> </a:commandLink> </f:facet> <h:outputText value="#{contacts.lastName}" /> </rich:column> <rich:column> <f:facet name="header"> <a:commandLink action="#{SalesPersonContacts.sortAction('firstName')}" reRender="contactsScroller,sp-contacts" style="text-decoration: none;" value="First Name"> <h:graphicImage value="../common/image/icon-edit.gif" style="text-decoration: none;"></h:graphicImage> </a:commandLink> </f:facet> <h:outputText value="#{contacts.firstName}" /> </rich:column> <rich:column> <f:facet name="header"> <a:commandLink action="#{SalesPersonContacts.sortAction('phone1')}" reRender="contactsScroller,sp-contacts" style="text-decoration: none;" value="Phone"> <h:graphicImage value="../common/image/icon-edit.gif" style="text-decoration: none;"></h:graphicImage> </a:commandLink> </f:facet> <h:outputText value="#{contacts.phone1}" /> </rich:column> <rich:column> <f:facet name="header"> <a:commandLink action="#{SalesPersonContacts.sortAction('email')}" reRender="contactsScroller,sp-contacts" style="text-decoration: none;" value="Email"> <h:graphicImage value="../common/image/icon-edit.gif" style="text-decoration: none;"></h:graphicImage> </a:commandLink> </f:facet> <h:outputText value="#{contacts.email}" /> </rich:column> <rich:column> <f:facet name="header"> <a:commandLink action="#{SalesPersonContacts.sortAction('address')}" reRender="contactsScroller,sp-contacts" style="text-decoration: none;" value="Street"> <h:graphicImage value="../common/image/icon-edit.gif" style="text-decoration: none;"></h:graphicImage> </a:commandLink> </f:facet> <h:outputText value="#{contacts.address}" /> </rich:column> <rich:column> <f:facet name="header"> <a:commandLink action="#{SalesPersonContacts.sortAction('city')}" reRender="contactsScroller,sp-contacts" style="text-decoration: none;" value="City"> <h:graphicImage value="../common/image/icon-edit.gif" style="text-decoration: none;"></h:graphicImage> </a:commandLink> </f:facet> <h:outputText value="#{contacts.city}" /> </rich:column> <rich:column> <f:facet name="header"> <a:commandLink action="#{SalesPersonContacts.sortAction('state')}" reRender="contactsScroller,sp-contacts" style="text-decoration: none;" value="State"> <h:graphicImage value="../common/image/icon-edit.gif" style="text-decoration: none;"></h:graphicImage> </a:commandLink> </f:facet> <h:outputText value="#{contacts.state}" /> </rich:column> <rich:column> <f:facet name="header"> <a:commandLink action="#{SalesPersonContacts.sortAction('zip')}" reRender="contactsScroller,sp-contacts" style="text-decoration: none;" value="Zip"> <h:graphicImage value="../common/image/icon-edit.gif" style="text-decoration: none;"></h:graphicImage> </a:commandLink> </f:facet> <h:outputText value="#{contacts.zip}" /> </rich:column> <rich:column> <f:facet name="header"> <a:commandLink action="#{SalesPersonContacts.sortAction('users.firstName')}" reRender="contactsScroller,sp-contacts" style="text-decoration: none;" value="Assignment"> <h:graphicImage value="../common/image/icon-edit.gif" style="text-decoration: none;"></h:graphicImage> </a:commandLink> </f:facet> <h:outputText value="#{contacts.users.firstName} #{contacts.users.lastName}" /> </rich:column> </rich:dataTable> </div></td> </tr> <tr> <td align="center" width="100%"> <div class="tab-box-footer"><rich:datascroller id="contactsScroller" align="center" selectedStyleClass="activeLinksScroller" tableStyleClass="tablefooter" inactiveStyleClass="inActiveLinksScroller" for="sp-contacts" maxPages="15" style="tablefooter" boundaryControls="hide" fastControls="hide" renderIfSinglePage="false" binding="#{spContactsAction.dataScroller}"> <f:facet name="previous"> <h:graphicImage value="../common/image/arrow-left.gif" height="14"></h:graphicImage> </f:facet> <f:facet name="next"> <h:graphicImage value="../common/image/arrow-right.gif"></h:graphicImage> </f:facet> <f:facet name="previous_disabled"> <h:graphicImage value="../common/image/arrow-left.gif"></h:graphicImage> </f:facet> <f:facet name="next_disabled"> <h:graphicImage value="../common/image/arrow-right.gif"></h:graphicImage> </f:facet> </rich:datascroller></div> </td> </tr> </table> </ui:define> </ui:composition>
When I run the application factory method 'listContacts' run
for the first time. But When I try to go to next page from the scroller. Again same data for factory method is loaded. And it shows me blank datatable. But when I come back to previous page from scroller the factory method loads the data for the page from which I have come to previous page. And current page is shown blank. And when I move to forward page again the data for previous page is loaded and this goes on.
I hope that u get my question. Please reply as soon as possible.
Bye
Muhammad Ali