I am having a problem with what I would have thought would be a very simple use of seam.
I have a Stateful component (using ejb's) and when I put the component in default
scope it doesn't work however in session scope it does. Here is the code;
| Stateful
| //(a)Scope(ScopeType.SESSION)
| @Name("userList")
| @Restrict("#{identity.loggedIn}")
| public class UserListImpl implements UserList {
| private static final int PAGESIZE = 10;
|
| @PersistenceContext
| private EntityManager em;
|
| private String searchUsername;
| private int pageNo = 0;
|
| @DataModel
| private List<User> users;
|
| public void findUsers() {
| System.out.println("findUsers:" + pageNo);
| pageNo = 0;
| loadCurrentPage();
| }
|
| private void loadCurrentPage() {
| System.out.println("loadCurrentPage:" + pageNo);
| String searchPattern;
| if (searchUsername == null) {
| searchPattern = "%";
| } else {
| searchPattern = '%' + searchUsername.toLowerCase().replace('*',
'%') + '%';
| }
| users = em.createQuery("from User where lower(username) like
:searchPattern")
| .setParameter("searchPattern", searchPattern)
| .setMaxResults(PAGESIZE)
| .setFirstResult(pageNo * PAGESIZE)
| .getResultList();
| }
|
| public String getSearchUsername() {
| return searchUsername;
| }
|
| public void setSearchUsername(String searchUsername) {
| this.searchUsername = searchUsername;
| }
|
| public boolean isNextPageAvailable() {
| return ((users != null) && (users.size() == PAGESIZE));
| }
|
| public boolean isPrevPageAvailable() {
| return (pageNo > 0);
| }
|
| public void nextPage() {
| System.out.println("nextPage:" + pageNo);
| pageNo++;
| loadCurrentPage();
| }
|
| public void prevPage() {
| System.out.println("prevPage:" + pageNo);
| pageNo--;
| if (pageNo < 0) {
| pageNo = 0;
| }
| loadCurrentPage();
| }
|
| public int getPageNo() {
| System.out.println("getPageNo:" + pageNo);
| return pageNo;
| }
|
| public void setPageNo(int pageNo) {
| System.out.println("setPageNo:" + pageNo);
| this.pageNo = pageNo;
| }
|
| @Create
| public void create() {
| System.out.println("create:" + pageNo);
| }
|
| @Remove
| @Destroy
| public void destroy() {
| System.out.println("destroy:" + pageNo);
| }
| }
|
| <!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/template.xhtml">
| <ui:define name="body">
|
| <h:messages globalOnly="true" styleClass="message"/>
|
| <rich:panel>
| <f:facet name="header">User List</f:facet>
|
| <h:form id="searchCriteria">
| <h:inputHidden id="pageNo" value="#{userList.pageNo}"/>
| <table>
| <tr>
| <td>
| <h:outputLabel
for="searchUsername">Username:</h:outputLabel>
| </td>
| <td>
| <h:inputText id="searchUsername"
value="#{userList.searchUsername}" size="15" />
| </td>
| <td>
| <h:commandButton id="findUsers" value="Find Users"
action="#{userList.findUsers}" reRender="searchResults"/>
| </td>
| <td style="width: 100%" align="center">
| <a href="usermaint.seam?userid=0">
| <img style="border: none" src="img/adduser32.gif"
width="32" height="32" /><br />
| Add a new User</a>
| </td>
| </tr>
| </table>
| <rich:separator height="2" style="padding:10px 0" />
|
| <div class="section">
| <s:div rendered="#{users != null and users.rowCount==0}">
| <table>
| <tr>
| <td><img src="img/warn48.png" width="48"
height="48" /></td>
| <td valign="middle"><span class="">No Users
Found</span></td>
| </tr>
| </table>
| </s:div>
| <rich:dataTable id="users" value="#{users}" var="u"
rows="20" rendered="#{users.rowCount>0}">
| <rich:column>
| <f:facet name="header">User Name</f:facet>
| #{u.username}
| </rich:column>
| <rich:column>
| <f:facet name="header">Full Name</f:facet>
| #{u.fullName}
| </rich:column>
| <rich:column>
| <f:facet name="header">Action</f:facet>
| <a href="usermaint.seam?userid=#{u.userId}"><img
style="border: none" src="img/edit15.gif" width="15"
height="15" /></a>Â
| <a href="#"><img style="border: none"
src="img/delete15.gif" width="15" height="15"
/></a>
| </rich:column>
| </rich:dataTable>
| <h:commandButton value="Previous Page"
action="#{userList.prevPage}"
rendered="#{userList.prevPageAvailable}"/>
| <h:commandButton value="Next Page"
action="#{userList.nextPage}"
rendered="#{userList.nextPageAvailable}"/>
| </div>
|
| </h:form>
| </rich:panel>
|
| </ui:define>
| </ui:composition>
|
The problem arises when I attempt to use the "Next Page" button. With the
component in session scope it works fine however with the component in default
conversation scope the userList.nextPage method is never called. Here is a copy of the
sysout;
| 18:29:16,234 INFO [STDOUT] create:0
| 18:29:16,265 INFO [STDOUT] getPageNo:0
| 18:29:16,281 INFO [STDOUT] setPageNo:0
| 18:29:16,343 INFO [STDOUT] getPageNo:0
| 18:29:16,359 INFO [STDOUT] destroy:0
|
Has anyone got any ideas as to why this occurs? I will be creating heaps of these
components and I don't want to have to stick them all in the users session since that
would be a waste of server resources.
Thanks in advance
-Mark
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119958#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...