2 Replies Latest reply on Oct 6, 2006 7:41 PM by Gavin King

    Paginator EJB and DataModel

    Monkey Den Master

      I have implemented a Paginator SFSB and use it within my Seam action (also SFSB). I expose the paginator itself to the web layer using @Out.

      Currently, the paginator's collection is annotated with @DataModel, and that works fine for rendering and paginating. The Seam action has the @DataModelSelection which obviously does not work correctly. The question I have is, can you annotate using @DataModel and @DataModelSelection in two different classes?

      A SFSB Paginator didn't seem right to me so I also thought about extending DataModel for the paginator, and annotating that with @DataModel in the Seam action, which is probably the right way to go.

      Thanks for the suggestions.

        • 1. Re: Paginator EJB and DataModel
          Monkey Den Master

          Gavin,
          I extended your ListDataModel for this and used @Out instead of @DataModel. My extension provides the methods used for pagination and sorting and, in doing so, attempts to manipulate the super classes attributes (rowCount, rowIndex and wrappedData). The exception I'm getting is:

          attempted to bind an Out attribute of the wrong type to: userSearchAction.paginator

          Everything works fine up until Seam attempts to outject it. Maybe I'm misunderstanding how your code works. Is it not simply outjected as a ListDataModel?

          Here is the relevant code:

          My Seam action

          public class UserSearchAction implements UserSearch
          @Out(required=false)
          private ListDataModelPaginator paginator;
          ...
          Query query = em.createQuery(query);
          paginator = new ListDataModelPaginator(query.getResultList());
          paginator.sort(ASC_NAME_COMPARATOR);
          ...
          }


          Paginator
          public class ListDataModelPaginator extends ListDataModel {
          
           private int rowsPerPage = 20;
          
           public ListDataModelPaginator() {
           super(new ArrayList());
           }
          
           public ListDataModelPaginator(List list) { super(list); }
          
           public ListDataModelPaginator(List list, Comparator comp) {
           super(list);
           }
          
           public void scrollFirst() {
           setRowIndex(0);
           }
          
           public void scrollPrevious() {
           setRowIndex(getRowIndex()-rowsPerPage);
           if (getRowIndex() < 0) {
           setRowIndex(0);
           }
           }
          
           public void scrollNext() {
           setRowIndex(getRowIndex()+rowsPerPage);
           if (getRowIndex() >= getRowCount()) {
           setRowIndex(getRowCount() - rowsPerPage);
           if (getRowIndex() < 0) {
           setRowIndex(0);
           }
           }
           }
          
           public void scrollLast() {
           setRowIndex(getRowCount() - rowsPerPage);
           if (getRowIndex() < 0) {
           setRowIndex(0);
           }
           }
          
           public boolean getIsScrollFirstDisabled() {
           return getRowIndex() == 0;
           }
          
           public boolean getIsScrollLastDisabled() {
           return getRowIndex() >= getRowCount() - rowsPerPage;
           }
          
           public boolean getIsScrollNextDisabled() {
           return getRowIndex() >= getRowCount() - rowsPerPage;
           }
          
           public boolean getIsScrollPreviousDisabled() {
           return getRowIndex() == 0;
           }
          
           public int getRowsPerPage() {
           return rowsPerPage;
           }
          
           public void setRowsPerPage(int rowsPerPage) {
           this.rowsPerPage = rowsPerPage;
           }
          
           public void setSortedList(List items){
           super.setWrappedData(items);
           super.setRowIndex(0);
           }
          
           public void sort(Comparator comp){
           List unsorted = (List)getWrappedData();
           Collections.sort(unsorted, comp);
           super.setWrappedData(unsorted);
           super.setRowIndex(0);
           }
          }


          • 2. Re: Paginator EJB and DataModel
            Gavin King Master

            Looks like you have a Seam component called "paginator" floating around somewhere in your project. Remove it.