Should I be able to pass a NotesDocumentCollection in a sessionScope variable? - xpages

I have one page that does a NotesDatabase search and of course returns a collection. I am storing that collection in a sessionScope variable and calling a page where I what ti display the results.
if ( collection1.getCount() == 0)
{
displayErrorMsg("Your search returned zero results. Please try another search.",getClientId("title"), "Zero Results");
}
else
{
sessionScope.put("searchResults",collection1);
var extCont = facesContext.getExternalContext();
extCont.redirect("xp_vwIssueSearchResults.xsp");
}
The page has a data table with the content of the scope variable as it's datasource:
sessionScope.get("searchResults");
When I call this page I get, NotesException: Object has been removed or recycled.
Should I be able to pass a NotesDocumentCollection in a sessionScope variable? I have some thoughts on work arounds but it would sure be nice to pass the NotesDocumentCollection.

You can't keep Notes objects like views, documents, collections for a longer time. In general, you should work with Notes object in a way, that you save the data you're interested in somewhere and recycle (=destroy) the Notes objects right away. The reason is that the Domino server can't save the Notes objects for you between two request because Notes objects aren't serializable (serializable = ability to save objects on disk and restore them back to memory).
In your case, you could save
the search query or
the result values as an Array of Objects (JavaScript) or a List of Maps (Java) or
the documentUniqueIDs of document collection's documents
in your sessionScope variable and use them in your redirected page.

Related

XPages : How to get document collection for dominoView datasource with 'search' property in SSJS

I filtered out XPages view with 'search' option. Then I'd like to access all of the documents by SSJS.
If I access the bound Notes view by database.getView("ViewName"), the view is not searched and could not get the searched result.
How can I access the document collection?
The dominoView data source is just a wrapper that runs calls on the underlying view to return a subset of entries to display in a view component (Data Table, View Panel, Repeat, Data View etc). Consequently, unless the rows property is set to a large enough value to get a handle on all responses, you’re unlikely to be able to access what you want that way.
The best approach will be to run the search on the backend view in SSJS / Java.
See https://www.intec.co.uk/understanding-xpages-views/ for a more detailed explanation of the different elements involved and their inter-relationships.

Retrieving multiple attachments with multiple documents

I'm building an app right now using couchdb, spring, and angularjs. On my UI I'm creating a document with attachments inside it (image) and I'm submitting them to my server which validates and then submits to the database. When I want to retrieve these documents to display them on the UI, first I call my view
function(doc) {
if(doc.type && doc.type === "type")
emit(doc._id, null);
}
I'm returning null as the second parameter because I read somewhere that it was better performance to not return the doc and to use includedocument = true request parameter. Once I have my list of documents, their attachments are only stubs and I need the data. So I make a new request for each document to get the document with the attachment. This feels very redundant and I feel like I'm doing it wrong. If this is the way I must do it, is there a better way performance wise? I'm thinking that since I have to retrieve the document again anyway to get the attachment, maybe I should leave out the includedocuments = true on my initial request since really all I need is the ID. What do you guys think?
In my opinion, you need to set includedocuments = false. After you get all id's of documents your need, just request them.
I think it's more universal way if you'll have some changes in logic in View. For example, you will need to sort docs by the type, and you will need to create more different views

How do you refresh document1 from the backend document

I have a process on the beforePageLoads that executes if it is a newDocument. It grabs a profile docuemnt that contains a number of fields that I need to copy into the XPage that is being loaded. I use the following code:
var iCol:Array = pDoc.getItems()
for(var i=0; i<iCol.length; i++){
var item:NotesItem = iCol[i];
var iName:String = item.getName();
if (#Left(iName, 2) == "AC" ){
iCol[i].copyItemToDocument(doc,"");
}
item.recycle()
} // for loop
where pDoc is the profile document and doc is backend document obtained by var doc = document1.getDocument(). I can then use the copyItemTODocument method and this works real well except I need to refresh the dataSource from the backend document. I can do this from a button and do a partial refresh but that is not an option in a production situation. I have tried various refresh options (suggested in this forum) but none of them get the job done. I can copy the values from the profile document fields to a filed in the datasource but this gets really messy because of data types. I believe my refresh problem is related to updating the doc not document1 in my code. Is there a way to refresh document1 from the backend document?
Does this help ..
http://xpagesblog.com/XPagesHome.nsf/Entry.xsp?documentId=84329CA285163DDF852578CB00669143
it hints at two things whcih may be osf use :
"It appears that during the initial PageLoad events the existing data is transferred from the NotesDocument to the NotesXspDocument. Only those fields bound to the NotesXspDocument (on XPage or CC) are transferred. "
and in the comments section:
"Another way of getting data from the XspDocument to the NotesDocument without a save, is to use document1.getDocument(true) which basically re-syncs the data between the two objects.
I don't have time to experiment I'm afraid but it looks like this is along the right lines, espcially the second part.
Doug

Use datasource to get backend document

I got a panel which bind to an open document as data source called document1 in an extlib dialog box. On button save, I want to compare all the field values between back-end document and document1. However, all the field values from back-end document are seemed to be updated therefore their field values are the same in document1. The comparison is done before docuemnt1.save().
From my understanding, document1.getDocument() should get the back-end document which all original/current data. document1.getDocument(true) should get all new data. I had try to getDocumentByID and found that all field values are updated in back-end document. I have no idea because document1.save not yet executed.
Why back-end document being updated with new data before save?
Is there any better way to get back-end document which all original/current data?
If you are using the the parameter true with the getDocument method, all changes done to the datasource are temporarly written to the datasoure's datastore.
The XPages engine is "smart enough" to realize that multiple instances of a NotesDocument object are all referencing the same backend document. It will now return the cached data from the datasource's datastore. That is why all objects will now return the updated values instead of the values stored in the backend document (Using of multiple datasources will give you the same result).
To access the data from the backend document, you can use a #DbLookup on a view with all documents sorted by their UNID.
#DbLookup("","AllByUNID", document1.getDocument( true ).getUniversalID(), "FIELD")

Symfony how to store many objects

in my symfony application there's a form to fill out and submit with ajax (the user can submit many times).
When the user submits the form, I would like to store the object somewhere (to save in the database later) and I was wondering where is the right place!
can anyone help me??
tnx
Jury D'ambros
The best answer really is saving the object to the database and maybe have a column in that table that flags the object as temporary.
Another approach could be saving the object to the user's attribute holder:
$object = new YourObject();
// deal with the form bind here
// ...
// i is an integer so you may have different attributes
$this->getUser()->setAttribute('ObjectName-'.i, $object);

Resources