QueryView: change SelectionQuery in XPages

Hi everyone, in these days i’m getting in the amazing world of Xpages and I found them really realy intersting!

I’ve got a domino 8.5 server set up with DB2 database enabled and i want to combine these two techologies.

My aim to change the “selectionQuery” property of the queryviews dinamically from a button or an js event from an Xpages and thus automatically refresh my elements in the xpage (View or dataTable or Repeater).

I think this would be amazing!

Have anyone tried this way?

Have you guys got some advice or hint to help me, please ?

Thanks everyone and go ahead with Xpages !!!

Marco

Subject: best option is probably using viewScope

Suppose you have a repeat control bound to the result of SSJS code that executes the following SQL:

“SELECT * from endusers WHERE clue > 0”

If you wanted, for example, to allow users to resort the repeat using links above the repeat, you could bind an event to each link to set an “ORDER BY” value:

viewScope.put(“repeatSortColumn”, “firstName”);

In the code your repeat is bound to, then, you could do something like this:

var SQL = "SELECT * from endusers WHERE clue > 0 ORDER BY " + (viewScope.get(“repeatSortColumn”) || “1”);

With this approach, when the page originally loads, the repeat will sort by the first column returned from the query, but when a user clicks a resort link the repeat will be resorted by the corresponding column.

Subject: RE:QueryView: change SelectionQuery in XPages

Hi Tim and thanks for your hint!

excuse my ingorance in xpages developing, i’m totally a newbie in this world…

the point I don’t understand is if is there some way to work with the property “selectionQuery” of the view used in the datasource of my ViewPanel (or repeat, or Data table).

My situation is:

I’m ve got a query view called “qvUser” with a selectionQuery = “SELECT * FROM DBDB2.MYDAV”; this fetch more than 100.000 records…

With LS, to get quick response, i used to do this:

<< LS CODE >>

v = db.getView(“qvUser”)

v.selectionQuery = “SELECT * FROM DBDB2.MYDAV WHERE FIELD1 = '” & param1 & “'”

v.Refresh()

<< END LS CODE >>

i do this everytime i do a search in the view.

Now with xPages i’d like to do the same:

suppose a editable textbox in the top used as search field.

Underneath i’ve got a Data Table which displays all the data from the view “QVUser”.

I want to automatically update the Data Table when the user type the search term.

I don’t know how to change the selectionQuery from inside the xPage and then reload the Data Table…

Do you know if anyone already did it, and if i can find some nsf to study as example ?

Thank you very much for your time !!

Marco

Subject: first step

Today i’ve been working on this point and this is what i got till now:

on a SSJS event (button onclick) i call a LS agent and whit this i’m able to change the selectionQuery on my queryview.

This is working good but i still cannot pass parameter which means i need to know the new selectionquery which can’t change dinamically.

In this post http://www-10.lotus.com/ldd/ddwiki.nsf/dx/reuse_lotusscript_xpage.htm Jo Grant use a intermediate document to store and read the parameter…

that’s a solution but I guess there’s something quicker!

any hint ?

Thanks

marco

Subject: SSJS not working

i forgot…i tried to write a SSJS on the onclock event, it was like this:

//chr is string variable containing "

v = database.getView(“qvUsers”);

v.SelectionQuery = chr + “SELECT …FETCH FIRST 10 ROWS ONLY” + ;

v.refresh();

and i put partial refresh on my View control…

it update the view data but not the selectionQuery → data still the same…

:frowning:

Subject: …

any idea ??

Subject: YES!!

It’s finally working !Here’s my solution:

// SSJS CODE in onclick() event

//setting variables

var strc = String.fromCharCode(34);

var strQry1 = “SELECT * FROM MYDB.MYTABLE WHERE MYFIELD = '”;

var strQry2 = “'”;

var QRY = getComponent(“inputText1”).getValue();

var peopleView:NotesView = database.getView(“MYQUERYVIEW”);

peopleView.setSelectionQuery(strc+ strQry1 + QRY + strQry2 + strc);

getComponent(“query”).setValue(strc+ strQry1 + QRY + strQry2 + strc);

I do hope this can help someone !

Have you got any comments or idea to improve it ?

Perfomance are not bad:

seeking in a 100.000 records table i get the response in the web page within 2 - 3 secs…

Marco

Subject: YES!!