Dan Soares
Dan Soares

Reputation: 380

XPage datatable and pager issue

On my XPage, I have a series of search filters (State, First Name and Last Name). The search button triggers the population of the datatable which is bound to a Managed Bean.

The datatable initially gets populated with rows of data. However when I click on Next (in the pager), instead of loading the next 5 rows, it returns no more data. I KNOW the datatable is getting the right number of rows because if I change the Repeat limit in the datatable to 10, they all display. Also, the number of pages in the pager is 2 (which is the correct number).

Any ideas what could be causing this?

Thanks,

Dan

Code for the datatable:

    <xp:dataTable rows="5" id="studentTable" var="currentStudent"
        style="width:400.0px" value="#{studentlist.students}">
        <xp:column id="firstnameColumn" style="font-weight:bold">
            <xp:this.facets>
                <xp:span xp:key="header">
                    <xp:span style="font-weight:bold">
                        First Name
                    </xp:span>
                </xp:span>
            </xp:this.facets>
            <xp:text escape="true" id="firstnameField"
                value="#{currentStudent.firstname}">
            </xp:text>
        </xp:column>
        <xp:column id="column1">
            <xp:text escape="true" id="middleinitialField"
                value="#{currentStudent.middleName}">
            </xp:text>
            <xp:this.facets>
                <xp:span xp:key="header">
                    <xp:span style="font-weight:bold">
                        Middle Name
                    </xp:span>
                </xp:span>
            </xp:this.facets>
        </xp:column>
        <xp:column id="lastnameColumn" style="font-weight:bold">
            <xp:this.facets>
                <xp:span xp:key="header">
                    <xp:span style="font-weight:bold">
                        Last Name
                    </xp:span>
                </xp:span>
            </xp:this.facets>
            <xp:text escape="true" id="lastnameField"
                value="#{currentStudent.lastname}">
            </xp:text>
        </xp:column>
        <xp:column id="idColumn">
            <xp:this.facets>
                <xp:span xp:key="header">
                    <xp:span style="font-weight:bold">ID</xp:span>
                </xp:span>
            </xp:this.facets>               
            <xp:text escape="true" id="computedField1"
                value="#{currentStudent.id}">
            </xp:text>
        </xp:column>
        <xp:this.facets>
            <xp:pager layout="Previous Group Next" xp:key="header"
                id="pager1" for="studentTable" partialRefresh="true">
            </xp:pager>
        </xp:this.facets></xp:dataTable>

Code behind the button:

    var state=getComponentValue('state');
    var firstName=document1.getItemValueString("firstName");
    var lastName=document1.getItemValueString("lastName");
    if(state == "--" || firstName == "" || lastName == "")
    {
    //do nothing
    }
    else{
    studentlist.setConnDB("jdbc:sqlserver://XX.XX.X.XX:1433;DatabaseName=dan_test");
    studentlist.setConnUserName("test");
    studentlist.setConnPassword("Password1");
    studentlist.setSQLQuery("SELECT FirstName,MiddleName,LastName,ID FROM TestStudents        WHERE FirstName Like '"+firstName+"%' AND LastName Like '"+lastName+"%' AND State = '"+state+"' ORDER BY LastName ASC");

Upvotes: 0

Views: 818

Answers (2)

Tony McGuckin - IBM
Tony McGuckin - IBM

Reputation: 316

I'm making some assumptions here without seeing your MBean code, but hope to point you in the right direction nonetheless...

Ensure you are restoring the datamodel within the studenLists bean during invocations of the getStudents() call. I see you have value="#{studentlist.students}" in the XSP fragment above... that should map to a getStudents() method on the bean returning a DataModel of Student objects or the like... presumably yes? So, a couple of things to bear in mind here... ensure the bean is in at least viewScope (preferably) and that you "restore the wrapped data" in the getStudents() method based on a non-transient buffer (eg: ArrayList that is holding the current set of filtered "student" objects - and make sure that the buffer of Student objects is serializable - critical for "Disk Persistence"!

If you use this approach, the Pager will always be "paging" against an up-to-date restored datamodel for each subsequent paging request posted against the current view - the page index etc being internally managed by the DataModel object.

eg:

1. No restoration:


    ...
    private transient DataModel studentSearchResults;
    private transient List searchResults;
    ...
    public DataModel getStudents() {
        if (null == studentSearchResults) {
            studentSearchResults = new ListDataModel();
        }
        return studentSearchResults;
    }

versus:

2. With restoration:


    ...
    private transient DataModel studentSearchResults;
    private List searchResults;
    ...
    public DataModel getStudents() {
        if (null == studentSearchResults) {
            studentSearchResults= new ListDataModel();
            if(null != searchResults){
                studentSearchResults.setWrappedData(searchResults);
            }
        }
        return studentSearchResults;
    }

Upvotes: 1

Paul Stephen Withers
Paul Stephen Withers

Reputation: 15739

Do you also lose the data if you add another button that just partially refreshes the dataTable? That should identify if it's a problem with managed bean properties being reset (in which case the contents of the dataTable would disappear) or a problem with paging (in which case they wouldn't).

Upvotes: 0

Related Questions