Xpages “filter by category name” with two fields values (Restricting a View to Multiple Categories)

我的梦境 提交于 2020-01-14 14:56:06

问题


I want to design a view that display only projects of selected customer and services, so I created a view that customer and service columns are categorized and a view panel for this view. If I put document1.getDocument().getItemValueString("Customer")

it works with a restrict single category. How I can do this with tow categorized columns.

Thanks in advance


回答1:


Could you implement a repeat within a repeat for this?

The first repeat would capture your first category. Then inside you have a panel and a repeat and the second repeat would further filter the datasource by the second category




回答2:


You cheat. Have one column that concatenates customer and project. Grab that column in your selection and split it in code.

Then use the selected value for the one column. Lets presume your original columns are customer and project. So your new column would have the formula customer+"~"+project. You then read this values to populate a SSJS object or a variable, so you can retrieve the customers (first dropdown) and the projects (second dropdown). In a dropdown you can use the format Display|Value, so a good approach is to have the value in the format customer~project.

As said you can do that in Java or JavaScript. Since I like Java's collection framework a lot, here's the Java version:

import java.util.Set;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;

import lotus.domino.Database;
import lotus.domino.NotesException;
import lotus.domino.View;
import lotus.domino.ViewEntry;
import lotus.domino.ViewEntryCollection;

public class SplitCategoryBean {

    private static final String SEPARATOR = "~";
    private final Map<String,Set<String>> allCategories = new TreeMap<String, Set<String>>();

    public void populate(Database db, String viewName) throws NotesException {
        View v = db.getView(viewName);
        ViewEntryCollection vec = v.getAllEntries();
        ViewEntry ve = vec.getFirstEntry();

        while (ve != null) {
            ViewEntry nextVE = vec.getNextEntry(ve);         
            this.addEntry(ve.getColumnValues().get(0).toString());
            ve.recycle();
            ve = nextVE;
        }

        vec.recycle();
        v.recycle();
    }

    private void addEntry(String combinedCategory) {
        String[] splitCategory = combinedCategory.split(SEPARATOR);
        String key = splitCategory[0];
        String value = splitCategory[1];
        Set<String> thisCategory = (this.allCategories.containsKey(key)) ? this.allCategories.get(key): new TreeSet<String>();
        thisCategory.add(value+"|"+combinedCategory);
        this.allCategories.put(key, thisCategory);       
    }

    public Set<String> getFirstCategory() {
        return this.allCategories.keySet();
    }

    public Set<String> getSecondCategoryReadyForDropDown(String key) {
        return this.allCategories.get(key);
    }

}

You would configure that as a managed bean (viewScope) and in the queryOpen you call the populate method. Then you can easily bind your first selection to #{beanName.firstCategory} for the selection and e.g. #{viewScope.curCustomer} for the value. The second drop-down you use the rendered="#{viewScope.curCustomer}" so it only shows when the customer is selected. And you bind the selections to #{javascript:beanName.getSecondCategoryReadyForDropDown(viewScope.curCustomer);

Put refreshs on the change events and render the view only if you have a project selected.

Does that work for you?




回答3:


Thanks guys

I created a view that the first column is categorized and its value is Customer+Service then put

document1.getDocument().getItemValueString("Customer") + document1.getDocument().getItemValueString(“Service")

in "filter by category name" of view panel it works now.



来源:https://stackoverflow.com/questions/26641321/xpages-filter-by-category-name-with-two-fields-values-restricting-a-view-to-m

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!