| Author |
Message |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 20/08/2009 13:09:24
|
hardaur
Joined: 30/09/2008 00:00:00
Messages: 11
Offline
|
Greetings!
I have a problem where I'm trying to use a @Factory method in an EntityQuery to avoid the JSF problems of calling EntityQuery.getResultsList() so many times. In general it works, however it seems as though on a request from IceFaces it's creating the Factory object before the query properties are updated.
From my list.xhtml:
Code:
<ice:form id="listFormId">
<ice:dataTable id="listDataTableId"
var="myEntity"
value="#{customResultList}"
rendered="#{not empty customResultList}"
width="100%">
And the factory method in the EntityQuery object:
Code:
@Factory(value = "customResultList", scope = ScopeType.EVENT)
public List customResultListInitializer()
{
List<Contest> resultList = super.getResultList();
return resultList;
}
Here's my page.xhtml facelet for grins (not particularly relevant, but since I use it as example):
Code:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
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:c="http://java.sun.com/jstl/core"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:s="http://jboss.com/products/seam/taglib">
<ice:form>
<table id="pagerTable" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<ice:commandLink
action="#{entityList.first}"
disabled="#{not entityList.previousExists}"
onclick="blur(); top.scroll(0,0);">
<ice:graphicImage url="#{entityList.previousExists ? '/images/pager_first_en.png' : '/images/pager_first_dis.png'}" style="border:none;"/>
</ice:commandLink>
</td>
<td align="center">
<ice:commandLink
action="#{entityList.previous}"
disabled="#{not entityList.previousExists}"
onclick="blur(); top.scroll(0,0);">
<ice:graphicImage url="#{entityList.previousExists ? '/images/pager_prev_en.png' : '/images/pager_prev_dis.png'}" style="border:none;" />
</ice:commandLink>
</td>
<td align="center">
<ice:selectOneMenu
value="#{entityList.currentPage}"
partialSubmit="true">
<s:selectItems value="#{entityList.pageList}"
var="page"
label="#{page}"/>
</ice:selectOneMenu> / #{entityList.pageCount}
</td>
<td align="center">
<ice:commandLink
action="#{entityList.next}"
disabled="#{not entityList.nextExists and entityList.currentPage ge entityList.pageCount}"
onclick="blur(); top.scroll(0,0);">
<ice:graphicImage url="#{entityList.nextExists or entityList.currentPage lt entityList.pageCount ? '/images/pager_next_en.png' : '/images/pager_next_dis.png'}" style="border:none;" />
</ice:commandLink>
</td>
<td align="center">
<ice:commandLink
action="#{entityList.last}"
disabled="#{not entityList.nextExists and entityList.currentPage ge entityList.pageCount}"
onclick="blur(); top.scroll(0,0);">
<ice:graphicImage url="#{entityList.nextExists or entityList.currentPage lt entityList.pageCount ? '/images/pager_last_en.png' : '/images/pager_last_dis.png'}" style="border:none;" />
</ice:commandLink>
</td>
</tr>
<tr>
<td align="center" style="font-size: .75em;">
First
</td>
<td align="center" style="font-size: .75em;">
Prev.
</td>
<td align="center" style="font-size: .75em;">
Go to Page (#{entityList.currentPage})
</td>
<td align="center" style="font-size: .75em;">
Next
</td>
<td align="center" style="font-size: .75em;">
Last
</td>
</tr>
</table>
</ice:form>
</ui:composition>
An example of the symptoms (just one example, is NOT paging specific, this is just easiest to communicate):
1. I load the page, everything's fine.
2. I click Next (using seam style paging through the EntityQuery, not icefaces paginator)
3. nothing happens (firstResult should now equal 2)
4. Hit next again
5. Shows me page 2 (firstResult should be 3, but is now 2)
6 etc.
The above values are printed out from the Factory method above. Sometime AFTER the factory method is called the values are updated so on the next request it shows what it should have shown previously. This make ANY sense at all? hehe
This is NOT paging specific as I said above. It does the same thing using EntityQuery restrictions as filters, changing maxResults() anything shows the same symptoms.
So just to try and say it in another way, this is what I thinks happening:
1. Load the page. everything's fine.
2. Click next (or filter or whatever) instantiate the factory
2.5 pass request data into seam (object already instantiated)
3 Render page
I've been beating my head against this for a couple days now so any help is VERY much appreciated.
Gerald
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 20/08/2009 13:14:31
|
lightguard

Joined: 11/05/2007 00:00:00
Messages: 165
Offline
|
Is there a reason you need it to be EVENT scoped? Does the result set need to constantly be refreshed with new data? If not consider using PAGE instead.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 20/08/2009 14:20:21
|
hardaur
Joined: 30/09/2008 00:00:00
Messages: 11
Offline
|
Yes, it has to update pretty much everytime there is a request so it applies filtering, sorting, paging, etc. Otherwise the dataset never changes since icefaces is ajaxish.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 20/08/2009 14:54:58
|
judy.guglielmin
Joined: 20/02/2007 00:00:00
Messages: 1196
Offline
|
But if you are using EntityQuery, it is redoing the query each time you change one of the parameters. (by using the pagination in this object, you are doing it all server-side) If you want it to be ajax-ish, then you would be using the datapaginators.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 20/08/2009 15:02:59
|
hardaur
Joined: 30/09/2008 00:00:00
Messages: 11
Offline
|
No, I'm just trying to update the resultList. Without the Factory EVERYTHING (it's a finished app, just doing performance tuning) works fine except for the standard JSF problem of a million repetitive queries. Since calling EntityQuery.resultList() as my value can't happen (due to JSF/queries) I have to create the factory object. I have to have the factory object in an event (request) scope or the dataset will never update until the user makes a call to the xhtml page.
I don't think what I'm doing is that unusual, it's pretty much boilerplate stuff as I understand it without the Factory thing. But in doing performance tuning I have to take care of the calls to getResultList to plug a BIG performance hole.
If I'm missing something big, I'm very willing to see things in a new light ; )
Thanks!
Gerald
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 20/08/2009 15:06:14
|
judy.guglielmin
Joined: 20/02/2007 00:00:00
Messages: 1196
Offline
|
How about trying the list (factory) being stateless
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 20/08/2009 15:14:05
|
hardaur
Joined: 30/09/2008 00:00:00
Messages: 11
Offline
|
Same thing as with event scope (I did try it). The @Factory method is being called BEFORE the request parameters are processed so it still thinks that it's running the old query. On the next request the query will execute with the criteria from the 1st request.
I think the problem may be a way Icefaces interacts with the JSF request cycle. Seam is firing the @Factory method before the icefaces request is getting processed. At least that's what it looks like.
Thanks again!
Gerald
Code:
@Factory(value = "customResultList", scope = ScopeType.STATELESS)
public List customResultListInitializer()
{
System.out.println("1 *****GETFIRSTRESULT = " + getFirstResult());
List<Contest> resultList = super.getResultList();
System.out.println("2 *****GETFIRSTRESULT = " + getFirstResult());
return resultList;
}
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 20/08/2009 15:20:08
|
judy.guglielmin
Joined: 20/02/2007 00:00:00
Messages: 1196
Offline
|
The conversation is not restored until after the restore_view phase, so it is the difference in handling the jsf lifecycle. The ICEfaces components are pretty much standard (unless you use the partialSubmit property) jsf lifecycle.
Did you try using the s:link components (rather than commandLink) and the page parameters (then you get a page refresh that changes the values and rebuilds the lists). The seam-gen templates use PAGE scope for this (since the entire page is refreshed each time).
|
|
|
 |
|
|