Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpages 在带有重复控件的表中显示类别总计_Xpages - Fatal编程技术网

Xpages 在带有重复控件的表中显示类别总计

Xpages 在带有重复控件的表中显示类别总计,xpages,Xpages,我有两类观点 第一个类别是分支名称,我从组合框中选择它并将其存储在viewScope变量中 第二个是年份,它应该是表的行标题。 另外还有12列,每列类似于一年中的一个月 这是我的视图,红色矩形是我希望在表中复制的结果 这是我目前在repeat control数据源方面的进展。但我不知道如何在计算字段上使用它 <xp:this.value><![CDATA[#{javascript:var db:NotesDatabase = session.getDatabase("

我有两类观点

第一个类别是分支名称,我从组合框中选择它并将其存储在viewScope变量中

第二个是年份,它应该是表的行标题。 另外还有12列,每列类似于一年中的一个月

这是我的视图,红色矩形是我希望在表中复制的结果

这是我目前在repeat control数据源方面的进展。但我不知道如何在计算字段上使用它

    <xp:this.value><![CDATA[#{javascript:var db:NotesDatabase = session.getDatabase("","erpx/report7.nsf", false);

var v = db.getView("(xpChartCostByProjectYear)");

var nav:NotesViewNavigator = v.createViewNavFromCategory(viewScope.project);
var entry:NotesViewEntry = nav.getFirst();
var vAccnt = db.getView("(chartCostByProject)");
var values = []; // create an empty array
while (entry!=null && !entry.isTotal()){
var obj={};
var year =[];
getComponent("computedField3").setValue(nav.getCount())

year.push(entry.getColumnValues().get(1));
obj.year = entry.getColumnValues().get(1);

obj.jan = entry.getColumnValues().get(2);
obj.feb =entry.getColumnValues().get(3);
obj.mar =entry.getColumnValues().get(4);
obj.apr=entry.getColumnValues().get(5);
obj.may=entry.getColumnValues().get(6);
obj.jun=entry.getColumnValues().get(7);
obj.jul=entry.getColumnValues().get(8);
obj.aug=entry.getColumnValues().get(9);
obj.sep=entry.getColumnValues().get(10);
obj.oct=entry.getColumnValues().get(11);
obj.nov=entry.getColumnValues().get(12);
obj.dec=entry.getColumnValues().get(13);
values.push(obj);


var tmpentry:NotesViewEntry = nav.getNextCategory();
entry.recycle();
entry = tmpentry;}

return values;

}]]></xp:this.value>

您希望在将代码绑定到任何东西之前简化代码。那么:

    var db = session.getDatabase("","erpx/report7.nsf", false);
    var v = db.getView("(xpChartCostByProjectYear)");
    var nav:NotesViewNavigator = v.createViewNavFromCategory(viewScope.project);
    var dataLabels = ["dummy","year","jan","feb ","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"]
    var entry:NotesViewEntry = nav.getFirst();
    var vAccnt = db.getView("(chartCostByProject)");
    var results = []; // create an empty array
    while (entry!=null && !entry.isTotal()){
        var obj={};
        var curVals = entry.getColumnValues();
        for (var i=1; i<14; i++) {
            obj[dataLabels[i]] = curVals.get(i);
        }

        results.push(obj);
        var tmpentry:NotesViewEntry = nav.getNextCategory();
        entry.recycle();
        entry = tmpentry;
    }
    //Cleanup
    nav.recycle();
    vAccnt.recycle();
    db.recycle();
    return results;
然后,您需要一个类
com.notessensei.ViewWithTotals
,该类可以容纳结果值,如果您不希望它们在查看页面时发生更改,甚至可以缓存它们

该类可以大致如下所示:

    package com.notessensei;

    import java.util.Collection;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Stack;
    import java.util.Vector;

    import lotus.domino.Database;
    import lotus.domino.NotesException;
    import lotus.domino.Session;
    import lotus.domino.View;
    import lotus.domino.ViewEntry;
    import lotus.domino.ViewNavigator;

    public class ViewWithTotals {

        private final String dataLabels[] = {"dummy","year","jan","feb ","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"};
        private final String dbName;
        private final String viewName;
        private final Map<String,Collection<Map<String,String>>> viewValues = new HashMap<String, Collection<Map<String,String>>>();
        private int totals = 42;

        public ViewWithTotals(String dbName, String viewName) {
            this.dbName = dbName;
            this.viewName = viewName;
        }

        public Collection<Map<String,String>> getRowData(Session session, String catName) {
            if (!this.viewValues.containsKey(catName)) {
                this.populateViewValues(session, catName);
            }       
            return this.viewValues.get(catName);
        }

        @SuppressWarnings("unchecked")
        private void populateViewValues(Session session, String catName) {
            try {
                Database db = session.getDatabase(null, this.dbName);
                View v = db.getView(this.viewName);
                ViewNavigator nav = v.createViewNavFromCategory(catName);
                ViewEntry ve = nav.getFirst();
                Collection<Map<String,String>> result = new Stack<Map<String,String>>();
                while (ve != null) {
                    ViewEntry nextVe = nav.getNextSibling(ve);
                    Map<String, String> oneEntry = new HashMap<String, String>();
                    Vector val = ve.getColumnValues();              
                    for (int i = 1; i < 14; i++) {
                        oneEntry.put(this.dataLabels[i], val.get(i).toString());
                    }
                    result.add(oneEntry);
                    ve.recycle();
                    ve = nextVe;
                }

                this.viewValues.put(catName, result);

                nav.recycle();
                v.recycle();
                db.recycle();
            } catch (NotesException e) {
                // TODO Fix this
                e.printStackTrace();
            }
        }

        // Exercise left to the reader...
        public int getTotals() {
            return this.totals;
        }
    }
package com.notessensei;
导入java.util.Collection;
导入java.util.HashMap;
导入java.util.Map;
导入java.util.Stack;
导入java.util.Vector;
导入lotus.domino.Database;
导入lotus.domino.NotesException;
导入lotus.domino.Session;
导入lotus.domino.View;
导入lotus.domino.ViewEntry;
导入lotus.domino.ViewNavigator;
带总计的公共类视图{
私有最终字符串数据标签[]={“虚拟”、“年份”、“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”};
私有最终字符串dbName;
私有最终字符串viewName;
private final Map viewValues=new HashMap();
私人整数总计=42;
public ViewWithTotals(字符串dbName、字符串viewName){
this.dbName=dbName;
this.viewName=viewName;
}
公共集合getRowData(会话、字符串catName){
如果(!this.viewValues.containsKey(catName)){
此.populateViewValues(会话、catName);
}       
返回此.viewValues.get(catName);
}
@抑制警告(“未选中”)
私有void populateViewValues(会话、字符串catName){
试一试{
Database db=session.getDatabase(null,this.dbName);
View v=db.getView(this.viewName);
ViewNavigator nav=v.createViewNavFromCategory(catName);
ViewEntry ve=nav.getFirst();
收集结果=新堆栈();
while(ve!=null){
ViewEntry nextVe=nav.getNextSibling(ve);
Map oneEntry=newhashmap();
Vector val=ve.getColumnValues();
对于(int i=1;i<14;i++){
oneEntry.put(this.dataLabels[i],val.get(i).toString();
}
结果。添加(一个条目);
ve.recycle();
ve=nextVe;
}
this.viewValues.put(catName,result);
回收资产();
v、 回收();
db.recycle();
}捕获(注e){
//该怎么办
e、 printStackTrace();
}
}
//留给读者的练习。。。
公共int getTotals(){
返回此.totals;
}
}
虽然这需要做更多的工作,但它应该可以为您提供a)更好的性能(您可以使用refresh()方法清除存储的值)和b)您可以添加其他值,用于绑定到其他字段(如此处的总计)。它提供了最好的灵活性

有一个经验:使用依赖注入(如:将会话作为参数提供),这样您也可以在XPages之外测试类(单元测试!)

希望有帮助。

注意:在我的头上键入代码。可能包含打字错误和语法问题

wow。。。这是一个很大的收获,但很有帮助。第一次剪短解决了我的问题。对我来说,这只是一个测试。但这门课将为我未来的项目创造奇迹。非常感谢。
    package com.notessensei;

    import java.util.Collection;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Stack;
    import java.util.Vector;

    import lotus.domino.Database;
    import lotus.domino.NotesException;
    import lotus.domino.Session;
    import lotus.domino.View;
    import lotus.domino.ViewEntry;
    import lotus.domino.ViewNavigator;

    public class ViewWithTotals {

        private final String dataLabels[] = {"dummy","year","jan","feb ","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"};
        private final String dbName;
        private final String viewName;
        private final Map<String,Collection<Map<String,String>>> viewValues = new HashMap<String, Collection<Map<String,String>>>();
        private int totals = 42;

        public ViewWithTotals(String dbName, String viewName) {
            this.dbName = dbName;
            this.viewName = viewName;
        }

        public Collection<Map<String,String>> getRowData(Session session, String catName) {
            if (!this.viewValues.containsKey(catName)) {
                this.populateViewValues(session, catName);
            }       
            return this.viewValues.get(catName);
        }

        @SuppressWarnings("unchecked")
        private void populateViewValues(Session session, String catName) {
            try {
                Database db = session.getDatabase(null, this.dbName);
                View v = db.getView(this.viewName);
                ViewNavigator nav = v.createViewNavFromCategory(catName);
                ViewEntry ve = nav.getFirst();
                Collection<Map<String,String>> result = new Stack<Map<String,String>>();
                while (ve != null) {
                    ViewEntry nextVe = nav.getNextSibling(ve);
                    Map<String, String> oneEntry = new HashMap<String, String>();
                    Vector val = ve.getColumnValues();              
                    for (int i = 1; i < 14; i++) {
                        oneEntry.put(this.dataLabels[i], val.get(i).toString());
                    }
                    result.add(oneEntry);
                    ve.recycle();
                    ve = nextVe;
                }

                this.viewValues.put(catName, result);

                nav.recycle();
                v.recycle();
                db.recycle();
            } catch (NotesException e) {
                // TODO Fix this
                e.printStackTrace();
            }
        }

        // Exercise left to the reader...
        public int getTotals() {
            return this.totals;
        }
    }