Wednesday, March 27, 2013

Creating simple xpages reports using data tables

What I am going to show in this post is how I created simple reports that the user can control.   I decided to use a data table to display the report data.

Before you start it looks like this.


The user then chooses the date selection, and the report auto populates.


Here is how I coded it:

For each report I created a separate custom control instead of adding directly to the xpage as I have done in the past.   At first I avoided custom controls, because I learned that they were like subforms, and I have found subforms to be more trouble than they are worth in the past.   Lately I have been working my way through Matt White's xpages101 series, and he does everything in custom controls.   I am starting to come around.

In the report custom control, I created a section, and in the section the combo box and the data table.   The data table is in a Div so that is partially refreshed using the onChange event of the combo box.

The onChange event simply sets a sessionScope variable for the user selection:

var approvedDate = getComponent("comboBoxCC1").getValue();
sessionScope.report1 = approvedDate;

The custom control is bound to a view that contains all documents categorized a single string.
var date = sessionScope.report1
var returnValue = document1.getItemValueString("Store") + "~" + document1.getItemValueString("Dept") + "~" + date
return returnValue


In the data table the computed fields are bound to specific columns of the view.

The only other piece of code is in the afterPageLoad event of the custom control, I added a line of code to clear the sessionScope variable.   This prevents the page remembering what was previously selected.  I experimented using a viewScope variable instead, but couldn't get it to work.
sessionScope.report1 = ""

I do realize that nothing here is particularly ground breaking, but I still wanted to document what I did for at least my own future reference. 

4/10 UPDATE:
I needed to make another copy of this report, and changed it so that combo box was bound directly to a ViewScope variable.   By doing this there is no need to set the variable to "".

No comments:

Post a Comment