Sharing new technologies and best practices

 
alt

Chris Connor

 
Follow ChrisJConnor on Twitter
Chat with me

XPages DataModels and Exporting to Excel

Chris Connor  May 4 2012 02:44:41 AM
Been doing a lot of work in XPages around Exporting - so naturally built a Java Class to run as a managed bean to do this. It extends the widely documented concept of SSJS Agents in that a button redirects to a page which renders the content as Excel or whatever.

So I thought - let the Excel class have different methods to do different things such as Export a view, a document collection and even the data used in a repeat control (essentially what is on screen). Package it up as an OSGI plugin and it can work for any app - sounds great.

However, the main problem that I am having with this centres around the repeat control export concept which is tied to a dataModel object. Consider the following piece of Java Code.

        public DataModel getRepeatModel(String repeatid) {
                this.repeat = (XspDataIterator) JSFUtil.findComponent(repeatid);
                this.datamodel = this.repeat.getDataModel();
                System.out.println("Repeat rows is "+this.repeat.getRows());
                System.out.println("Data Model Row Count on initial get is = "+this.datamodel.getRowCount());
                return this.datamodel;
        }


Frstly the repeat.getRows() returns 30 = which is to be expected as that is the number of rows that we specifiy in the repeat control. Thats fine ... but....

It seems the dataModel.getRowCount returns 246 documents - even although there are 500+ there. I believe (not confirmed -Wei mentioned this in my blog a while back a while ago that he was having a similar issue) that there is some sort of buffering going on - this could be stopping the processing past this number. Is there a way around this? Is there a better way?

The javax.faces.model.DataModel class is a standard JSF class with methods for things like getRowData() and setRowIndex() which allow you to traverse the structure and seem ideal for this sort of task. Of course if it IS buffering then I am sort of stuck and its workaround time...

One simple idea to get around this could be to to pass in the exact same Full Text Search String that is present for the repeat control. Then I would write a method that runs a second full text search and then process that data. I did something similar a while ago for XDesk on OpenNTF  with its excel export (as we are basically doing a double hit - one to display the data in the repeat from and then again another to export it). It is a full text search so performs well though....but not "optimal" - hate the idea of doing a double hit.

Any ideas on the dataModel class or a different approach would be welcome!

Sure an efficient approach that runs as an OSGI plugin to be shared over all your apps would benefit everyone!
Comments

1Niklas Heidloff  05/04/2012 6:42:42 AM  XPages DataModels and Exporting to Excel

have you seen? { Link }

2ChrisC  05/04/2012 6:48:56 AM  XPages DataModels and Exporting to Excel

Niklas,

Thanks - will have a look - see if there is anything I can glean in there. Talking to Paul Withers - he mentions there may be a way around the buffering worth investigating.

So I will also try looking at the alwaysCalculateLast property - see if that allows me to catch the full data set.

Will report back!

3Andrew Reeve  08/30/2012 4:55:28 AM  XPages DataModels and Exporting to Excel

I believe that if you have used a FTSearch on a view then the view entry count will return the number of documents that match the FTSearch query - not the total number of documents

If the dataModel is a view then view.clear() will clear the FTSearch query

About Me

Java / Web Development consultant with 17 years experience. Focus on XPages, Java / JSF / J2EE, Websphere Portal, Spring / Hibernate, RCP, jQuery, Dojo, RCP, Eclipse, RAD, Phonegap and general Mobile development. Experienced public speaker at several global events.

My day job is building Web applications for my customers using the best technologies for the job. This blog discusses the issues in delivering these modern collaborative solutions.

I am available for hire through my business BSS IT Solutions. We are an IBM Business Partner based in Scotland serving the UK and beyond!