-
1. Re: factory method with defined scope outjected a value
hasan_muhstaq Jun 13, 2008 12:37 PM (in response to nasir.imtiaz)Don't annotate ur Factory method, annotate the varriable thats used for outjection
// annotate with event / Page @DataModel(scope = ScopeType.EVENT) private List<Contacts> lstContacts; @Factory(value="lstContacts") public void getContacts() { lstContacts = some query thru database... }
-
2. Re: factory method with defined scope outjected a value
nasir.imtiaz Jun 13, 2008 2:04 PM (in response to nasir.imtiaz)Thanks hasan for your reply. But i tried your suggestions and unfortunately they didnt work.
When i tried to set scope of @DataModel to EVENT it threw
Caused by: java.lang.IllegalArgumentException: @DataModel scope must be ScopeType.UNSPECIFIED or ScopeType.PAGE: SalesPersonContacts
and when i set the scope to PAGE it shows me the first page of datascroller but when i click the 2nd page it throws exceptionjava.lang.IllegalStateException: No page context active
Any help would be great. -
3. Re: factory method with defined scope outjected a value
gjeudy Jun 13, 2008 3:54 PM (in response to nasir.imtiaz)Can you explain why you try to use EVENT scope ? I didnt have to use it in my Seam app. It seems like many people don't know that using CONVERSATION scope may do just as well even if you don't promote your conversation to a long-running one.
So why declare SalesPersonContact bean in SESSION scope ? If you declare it in CONVERSATION scope your @DataModel will implicitely be in CONVERSATION scope. Then all that you have left is control your conversation boundaries. If you dont the implicit CONVERSATION lasts for one full request cycle.
-
4. Re: factory method with defined scope outjected a value
newion Jun 15, 2008 5:03 PM (in response to nasir.imtiaz)If you want factory method to refresh your data (lstContacts in your case) set the data null
lstContacts = null
-
5. Re: factory method with defined scope outjected a value
dan.j.allen Jun 15, 2008 6:38 PM (in response to nasir.imtiaz)Well said. The problem here is that you are putting your SFSB in session. If you are using Seam, then you really don't need to be using session scope. If you want to use session and have the factory method called again, what you want to do is nullify the list in an action method and on the next view it will be fetched again.
Setting the @DataModel scope to PAGE should work too. I'm not sure I understand why you are getting
page context is not active
. -
6. Re: factory method with defined scope outjected a value
ali1983 Jun 25, 2008 9:26 AM (in response to nasir.imtiaz)
hasan mushtaq wrote on Jun 13, 2008 12:37:
Don't annotate ur Factory method, annotate the varriable thats used for outjection// annotate with event / Page @DataModel(scope = ScopeType.EVENT) private List<Contacts> lstContacts; @Factory(value="lstContacts") public void getContacts() { lstContacts = some query thru database... }
Hello mr Hassan Mushtaq.
I am having the problem in binding the UIDatascroller with UI. everything is working fine. But the problem is I am unable to set the page of datascroller through my backing bean.
I have two classes one with Event scope and other with Session scope
FactoryClass with Event scope
@Name("factoryClass") @Scope(ScopeType.EVENT) public class FactoryClass { @In(create = true) PrinterScansService printerScansService; @In(create = true) GroupService groupService; @In(create = true) PCUserSession pcUserSession; @In(create = true) UserService userService; @In(create = true) SalesPersonDashboardBean SalesPersonDashboard; @SuppressWarnings("unused") @DataModel private List<Printerscans> lstPrinterscans; @SuppressWarnings("unchecked") @Factory(value = "lstPrinterscans") public void listPrinterscans() { System.out.println("----- OrderField ----- "+ SalesPersonDashboard.getOrderField()); List listSubSetRecords; List lstGroups; Set setSPsOfGroups; int pageFirstIndex; Long count; lstGroups = groupService.getGroupsForSP(pcUserSession.getUserNumber()); setSPsOfGroups = userService.getSPsFromSalesGroups(lstGroups); count = printerScansService.getPrinterscanRowCount(userService .getCSVUserNumber(setSPsOfGroups)); Vector vector = new Vector(); vector.setSize(count.intValue()); pageFirstIndex = (SalesPersonDashboard.getDashboardDataScroller().getPage() * SalesPersonDashboard.getDashboardDataScroller() .getDataTable().getRows()) - SalesPersonDashboard.getDashboardDataScroller().getDataTable().getRows(); listSubSetRecords = printerScansService.getPrinterscansOfSPs( userService.getCSVUserNumber(setSPsOfGroups), SalesPersonDashboard.getOrderField(), SalesPersonDashboard.isAscendingOrder(), pageFirstIndex); for (int index = 0; index < listSubSetRecords.size(); index++) { vector.set(pageFirstIndex + index, listSubSetRecords.get(index)); } lstPrinterscans = vector; } public void nullList(){ this.lstPrinterscans = null; }
SalesPersonDashboardBean with SESSION scope
@Scope(ScopeType.SESSION) @Name("SalesPersonDashboard") public class SalesPersonDashboardBean { @In(create = true,required=false) FactoryClass factoryClass; public boolean ascendingOrder; public String orderField; @Out(value="dashboardDataScroller") UIDatascroller dashboardDataScroller; public void sortAction(String field) { this.ascendingOrder = !this.ascendingOrder; this.orderField = field; // this.dashboardDataScroller.setPage(1); // System.out.println("DataScroller Page: " + factoryClass.dashboardDataScroller.getPage()); factoryClass.listPrinterscans(); } public boolean isAscendingOrder() { return ascendingOrder; } public void setAscendingOrder(boolean ascendingOrder) { this.ascendingOrder = ascendingOrder; } public String getOrderField() { return orderField; } public void setOrderField(String orderField) { this.orderField = orderField; } public UIDatascroller getDashboardDataScroller() { return dashboardDataScroller; } public void setDashboardDataScroller(UIDatascroller dashboardDataScroller) { this.dashboardDataScroller = dashboardDataScroller; }
UI in which I am doing the binding
<rich:datascroller id="printerScanScroller" align="center" selectedStyleClass="activeLinksScroller" tableStyleClass="tablefooter" inactiveStyleClass="inActiveLinksScroller" for="sp-printerscans" maxPages="15" style="tablefooter" boundaryControls="hide" action="#{factoryClass.nullList}" binding="#{SalesPersonDashboard.dashboardDataScroller}" fastControls="hide" renderIfSinglePage="false"> <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>
In this scenario CONVERSATION scope is not working. The thing is that I want to reset my datascroller to page 1. And I am trying to do this in SalesPersonDashboard.sortAction() method. But it is not working. Other binding properties are working fine of UIdatascroller.
One more thing If u don't mind can I have your personal email address and phone number for help in further problems regarding seam.
Bye
Muhammad Ali