This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Sep 20, 2011, 9:05 PM
94 Posts

How can I retain values of editable fields in a Repeat control when the user pages fwd and back?

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags:
  • Replies: 3
I'm displaying an array of data in a Repeat control that comes from a query.  Each row contains editable fields.  The OnChange event of each editable field stores the entered values in an external (to the repeat) field bound to a sessionscope var for use later.  The editable fields are not bound to anything, and this all works.  However... now I realize that my users will likely fill in some fields, page forward, fill in some more and then maybe page back and expect their values on page one to still be there.
 
I tried to bind the editable field to a requestscope and even a sessionscope var dynamically with this
 
     var indexstr = String(index + 1);
     "#{sessionScope.UnitPrice_" + indexstr + "}" 
 
 where "index" is my Repeat index name.
(the field must be computed on page load and the Repeat must be set to create controls on page load)
 
I've used this before when binding to actual document fields.  But, this doesn't work for my scoped vars.  When I fill in some values, page forward and then back, my entries are gone.
 
So, how do I bind my editable fields to something that will retain their value when the user pages forward and back?
 
If this isn't possible, then I guess I could change my Repeat limit to 1000 or something, but I'd rather not do that.
Sep 20, 2011, 11:52 PM
25 Posts
Re: How can I retain values of editable fields in a Repeat control when the user pages fwd...
 Bob,
 
You could always make a sessionScope managed bean and store the value in a hash map in the bean. A hash map is simply a key/value pair. So once you setup your bean you could access it via SSJS like:
 
MyBean.setFieldValue(unid,value);
 
and to get the value: 
 
MyBean.getFieldValue(unid); 
 
This is assuming you have methods in the bean called setFieldValue and getFieldValue that would just get values from the stored hash map and add values to the hash map. Of course if it's more than just one field that's editable you would need to add additional logic for that.  Here are some excellent articles on using managed beans:
  
http://www.mindoo.de/web/blog.nsf/dx/16.07.2009095816KLEBCY.htm?opendocument&comments 
http://xpages.info/XPagesHome.nsf/Entry.xsp?documentId=4B1849D9F0F5EDC0852578CB0066BD27 
http://xmage.gbs.com/blog.nsf/d6plinks/TTRY-8GK6K7 - This is more the theory/introduction to managed beans 
http://blog.mindoo.com/web/blog.nsf/dx/18.03.2011104725KLEDH8.htm 
 
You could also setup a hash map via SSJS in a scoped variable and skip the managed bean part: 
 
var myMap:java.util.HashMap = new java.util.HashMap(); 
sessionScope.put("myValueMap",myMap); 
sessionScope.get("myValueMap").put(unid,value); 
 
var myValue = sessionScope.get("myValueMap").get(unid); 
 
Either way should provide a fairly robust solution. However using a bean would provide more room for expansion and data manipulation than a pure SSJS solution,  but it does require a bit more time putting it all together.
 
HTH 
Keith 
Sep 22, 2011, 1:23 PM
94 Posts
Re: How can I retain values of editable fields in a Repeat control when the user pages fwd...
Thanks Keith... I'll definitely read up on that.
 
One thing though... for my key-value pairs, the key value will need to come from each row of the repeat.  I thought I could use the repeat index value (which I called "index") for that, but when I try to get it for the editable field, I get an error "'index' not found".  Not sure why, so I then tried to get the value of the first field in the row with getComponent("ReqNo").  That didn't work either, getComponent() is null.
 
So, how can I use a key value from the repeat row, if I can't use the repeat index or the value of one of the fields in the row???  Am I missing something here?
Sep 23, 2011, 12:46 AM
25 Posts
Re: How can I retain values of editable fields in a Repeat control when the user pages fwd...
 Bob,
 
Me personally I like using the UNID. Once you get that, you can get the document and do anything you want with it. And since you're storing this info in a Map, you can just loop through that Map, get each document and do whatever with it. But if you must use the index try:
 
var rowsArray = getComponent("repeatControlId").getValue(); 
var doc:NotesDocument = rowsArray[index + 1]; 
 
Also, be sure to set the index name and collection name but I think you already did this.
 
HTH 
Keith 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal