Friday, January 29, 2010

Show Single Category (double Category) Lookup in Xpages Views

If we need to do a show single categories in XPages it is easy to do. The "CategoryFilter" in the data session will help to do that. But to make a double filter we need to do a little tweek with Search.

Single category(Category Filter) in Xpages:
  • Create a view with first column "sorted"(let me call the view as "xview")
  • Create an Xpage

  • Create a combo box in the Xpage and write the code to get the value of 1st column of the created view(xview)
  • Create a view control and map the newly created view (xview)
  • Neglect the 1st column in the displaying of view, since we don't need that.
  • Select the "CategoryFilter" Property and give the code "sessionScope.get("urchoice");" //This line of code is getting the value of the session scope variable and set the views property inorder to show the Single Category value from view.


  • Now write the code in the "combobox" in the onclick / on change and code the script "sessionScope.set("urchoice",getComponent("comboBox1").getValue()); //This line will get the selected value of the combobox and set in the sessionscope variable.
  • Now run the Xpages and see the "ShowSingleCategory" in the Xpages.

How can we create a Double Category that means filtering the view with Two Field values:


  • Remember to  index the database first
  • Create a view with first and second column "sorted"(let me call the view as "xview")
  • Create an Xpage
  • Create two combo box(s) in the Xpage and write the code to get the value of 1st column in the first combobox and 2nd in the second combobox of the created view(xview)
  • Create a view control and map the newly created view (xview)
  • Neglect the 1st 2 columns in displaying of view, since we don't need that.
  • Now create a Button in the Xpage called "Go" or "Submit", change the Button type to "Submit" (from properties)
  • Tie up the combobox value with the session scope and give the variable name (need to do for both combobox)


  • Select the view and select the "Search" (from properties) and write the code to get the correct documents in the view

This is a workaround for the double Filtering in the Xpage. This is a solution for the search also in Xpages.

Best way to handle ?ReadViewEntries for Lookup

?ReadViewEntries allows a view to be represented purely as XML.
Think about the a view contain more that 10k documents, it will be difficult to get the return value in for the use of Ajax DbLookup. This will sometime return you only specific values not all the values as you expect if you give the "count" parameter as well. As a work around rather than using the &Count parameters use, get the value you need to lookup and pass "&StartKey=valuetolookup&StartType=text", this will result you a faster search with only needed value(s).

The other optional parameters for the ?ReadViewEntries are

Collapse=n

CollapseView

Count=n

Expand=n

ExpandView

KeyType=text|time

ResortAscending=column number

ResortDecending=column number

RestrictToCategory=category

Start=n

StartKey=string

UntilKey=string