0

プラグイン(拡張ライブラリなど)の場合、指定された「var」名でデータソースにアクセスしようとします。次のコードを使用すると、データソースオブジェクトへのアクセスが非常に簡単になります。

m_DataSourceNameには、データソースの名前(var)が含まれます。

public DataSource getDataSource() {
    if (StringUtil.isNotEmpty(m_DataSourceName)) {

        UIViewRoot vrCurrent = getFacesContext().getViewRoot();
        if (vrCurrent instanceof UIViewRootEx) {
            for (DataSource dsCurrent : ((UIViewRootEx) vrCurrent)
                    .getData()) {
                if (m_DataSourceName.equals(dsCurrent.getVar())) {
                    return dsCurrent;
                }
            }
        }
    }
    System.out.println("Datasource name:" + m_DataSourceName);
    return null;
}

データソースを取り戻し、このデータソースをキャストできます。

private TabularDataModel getTDM(DataSource dsCurrent, FacesContext context) {
        try {
            if (dsCurrent instanceof ModelDataSource) {
                ModelDataSource mds = (ModelDataSource) dsCurrent;
                AbstractDataSource ads = (AbstractDataSource) mds;
                ads.load(context);
                System.out.println(ads.getBeanId());
                if (ads.getBeanId() == null) {

                }
                DataModel tdm = mds.getDataModel();
                if (tdm instanceof TabularDataModel) {
                    TabularDataModel tds = (TabularDataModel) tdm;
                    return tds;
                }
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

そして今、TDM.getRowCount()にアクセスしたいのですが、この時点でnullpointer例外が発生しています。データソースにはメモビューが含まれています。データソースを初期化するために何かを逃しましたか?

4

1 に答える 1

1

これがあなたの問題の解決策です:

これにより、エントリ数*ではなく、ビューのすべてのが表示されます。5つのカテゴリと各カテゴリに1つのエントリを持つ分類されたビューがある場合、これは10行になります。エントリー数は5です。

まず、FacesDataIteratorを実装するダミークラスを作成します

public class DummyDataIterator implements com.ibm.xsp.component.FacesDataIterator{

    public DataModel getDataModel() {
        return null;
    }

    public int getFirst() {
        return 0;
    }

    public int getRowIndex() {
        return 0;
    }

    public int getRows() {
        return 0;
    }

    public void setFirst(int paramInt) {}

    public void setRows(int paramInt) {}
}

そして、次のことを行う必要があります。

  1. データイテレータを設定する

    tdm.setDataControl( new DummyDataIterator() );
    
  2. 行カウンターを初めて初期化する

    tdm.getRowCount();   
    
  3. ナビゲーターを使用して正確な行数を計算します

    (( com.ibm.xsp.model.domino.viewnavigator.NOIViewNavigatorEx) tdm.getDominoViewDataContainer().getNavigator()).calculateExactCount(tdm.getView());
    

これで行数が初期化され、通常のgetRowCountで結果を取得できます。

System.out.println("Rows: " +  tdm.getRowCount() );

お役に立てれば!

*

tdm.getView().getAllEntries().getCount()
于 2012-12-14T07:47:17.597 に答える