Tuesday, May 19, 2009

Xpages: Picklist Views and the pager

If you create a picklist from a view like i posted yesterday, make sure you set the pager to partial refresh on your views, or else it will refresh the entire page and your dialog will go back to being hidden.



Monday, May 18, 2009

Xpages: How to create a view picklist!!

So i finally figured it out, by piecing many sources of code from around the internet.


Updated to say go get the custom control on Openntf.org!!!
It is much easier to use and set up.  It is also reusable.


Step 1. create a custom control.

Create a custom control and put your view on it, and put a search bar and a select button above it like this, make the first column have a check box option


Configure this for searching.... click here if you do not know how to do this.

On the select button "on click" event put this code in, it gets the selected documents, then it gets a value from the document and then adds it to the field on my main form. I got this code form the developer wiki

function printToLog(stuff) {
_dump("\r\nPRINT START\r\n");
_dump(stuff);
_dump("\r\nPRINT END\r\n");
}

var database = session.getDatabase("notes1", "applications\\viewpoint.nsf")
var viewPanel=getComponent("viewPanel1"); //get the componet of viewPanel
var docIDArray=viewPanel.getSelectedIds(); //get the array of document ids
printToLog('got ids')

for(i=0;
i  <  docIDArray.length;
i++){
var docId=docIDArray[i];
printToLog(docId)
var doc=database.getDocumentByID(docId);
printToLog(doc)
if(doc != null){
var pickthis1 = doc.getItemValueString("projectnum")
printToLog(pickthis1)
}
}

if(pickthis1 != null){
dominoDocument1.replaceItemValue("job", pickthis1)
}


On the client side of the select button js on click event, enter this in
dijit.byId('Dialog3').hide();


This closes the dialog we will create in a moment. Save and close that custom control.

On your main form you need to add this client side javascript function, i found this on the forum, unless you use this you can not click any buttons on your dialog or search or update.
/**
* Creates a dijit dialog box based on a div content
* @param id div identifier
*/

function dialog_create(id, title1) {
var dialogWidget = dijit.byId(id);
if( dialogWidget )
dialogWidget.destroyRecursive(true);
dialogWidget = new dijit.Dialog(
{ title: title1, duration:600},
dojo.byId(id));

var dialog = dojo.byId(id);
dialog.parentNode.removeChild(dialog);

var form = document.forms[0];
form.appendChild(dialog);
dialogWidget.startup();
}


Next add this to the source of your page, notice the<> is the picklist custom control we just created



At the top of the XPage in source view, you need to add the onload function to call the function to create the dialog

Then we create a button to show the dialog with client side javascript.
dijit.byId('Dialog3').show()

Then you will have something that works like a picklist, once you do it once it gets much easier.

moz-screenshot

example

Thursday, May 14, 2009

Xpages: Has anyone created a picklist yet?

I was wondering because it would be nice to have a button to pop up a dialog with a view in it, have check boxes and be able to return values back to the underlying webpage when done.

I have created a dialog inside an iframe for a simple pop up form, so i am familiar with that step. I guess i could put an xpage view inside the dialog and then when the select button is pushed, transfer the values, but how would one get the values of the selected document?

Any help is appreciated, this seems to be the only big thing missing from xpages, and maybe they will add an @picklist function in the future