0

I'd like to use com.ibm.xsp.model.domino.DominoViewData() in my Java class to filter and sort domino view data, but I'm not sure how to go about it.

There aren't a lot of examples out there, and most I've found are using it on an xPage or with a Data Table.

In a JAVA class, I'd like to:

  • Create a new DominoViewData object.
  • Set the view name.
  • Set the column to sort on.
  • Optionally set a filter.
  • Finally, retrieve a ViewEntryCollection for further processing.

Can the DominoViewData class be used in that way?

Thanks for your help and any examples would be appreciated.

-- Jeff

Jeff Byrd
  • 163
  • 1
  • 6

1 Answers1

1

As long as your are using them in an XPage application, this is possible. I am not sure what benefits you will have instead of accessing a view directly, but here is the code:

1.You need a helper class to access the tabular data model

/**
 * Returns the tabular data model from a datasource
 * 
 * @author Christian Guedemann, Sven Hasselbach
 * @param dsCurrent
 *   datasource to get the tdm from
 * @param context
 *   current FacesContext instance
 * @return
 *   TabularDataModel
 */
public static TabularDataModel getTDM(DataSource dsCurrent, FacesContext context) {
    try {
        if (dsCurrent instanceof ModelDataSource) {
            ModelDataSource mds = (ModelDataSource) dsCurrent;
            AbstractDataSource ads = (AbstractDataSource) mds;
            ads.load(context);
            DataModel tdm = mds.getDataModel();
            if (tdm instanceof TabularDataModel) {
                TabularDataModel tds = (TabularDataModel) tdm;
                return tds;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

2.You have to create your datasource and add them to a component, f.e. the view root

DominoViewData dvd = new DominoViewData();
dvd.setViewName( "YOUR VIEW NAME" );
dvd.setComponent( FacesContext.getCurrentInstance().getViewRoot() );

3.Now you can add the filter options or any additional options to your datasource, f.e. these:

dvd.setSortOrder( "ascending" );
dvd.setSortColumn( "NAME OF COLUMN" );

4.Then access the TDM of the datasource, get the first entry and you have a handle to the parent, a ViewNavigator

TabularDataModel tdm = getTDM( dvd, FacesContext.getCurrentInstance() );
tdm.setDataControl( new UIDataEx() );
Entry noiEntry = (Entry) tdm.getRowData();
ViewNavigator nav = null;
try {
    nav = (ViewNavigator) noiEntry.getParent();
    System.out.println( "NAV COUNT: " + nav.getCount() );
    nav.recylce();
} catch (NotesException e) {
    e.printStackTrace();
}

(OK, you now have a ViewNavigator instead of a ViewEntryCollection)

Sven Hasselbach
  • 10,455
  • 1
  • 18
  • 26