3
votes

I have a field named "selectedTime" in a document, this fields stores the selected timings added by user.Adding times is working perfect.This is back-end.

Now I will explain this issue of selecting date from front end.I have given a button add to add times.The custom control of date-time gets added to repeat control on click of Add button.Even if I check in document it shows the list of selected times.Even this works fine.

Now if I want to delete a selected time from repeat control randomly, it deleted that particular record from document, but on the page the last record of the repeat gets disappears,

I was assuming that this is the issue with partial refresh of repeat control,I have even tried that but no result.Full refresh breaks the page.

java script code for the delete button

`var doc:NotesDocument = database.getDocumentByUNID(context.getUrlParameter("refId"))
var selectedTimes:java.util.Vector = doc.getItemValue("selectedTimes");
if(selectedTimes != null){
var sdtString =  getComponent("inputHidden1").getValue();
if(selectedTimes.contains(sdtString))
selectedTimes.remove(sdtString);
doc.replaceItemValue("selectedTimes",selectedTimes);
doc.save();
};
var url:XSPUrl = context.getUrl();
view.postScript("window.refresh('"+url+"')");`

I know it is difficult to understand what i want to explain but any suggestion on this will be appreciated.

Even if anybody have any idea to delete the a field values of a documents,In my case field name is "selectedTimes" and the values are added times in repeat control, Please share.

Edit 1:

//Repeat Control

var doc:NotesDocument = database.getDocumentByUNID(context.getUrlParameter("refId"))
var selectedTimes:java.util.Vector = doc.getItemValue("selectedTimes");
return selectedTimes;
1

1 Answers

0
votes

Another try could be link the repeat with a viewScope instead of the document:

1) In the event beforeLoadPage/afterLoadPage: Get the value from the document, and put it in a viewScope variable:

// beforeLoadPage event:
// ... get the doc
viewScope.selectedTimes = doc.getItemValue("selectedTimes");

2) In the repeat control, use the viewScope:

<xp:repeat value="#{viewScope.selectedTimes}"...

3) When an update is done, update both the viewScope and the document:

//...update the View Scope variable and get the document:
doc.replaceItemValue("selectedTimes", viewScope.selectedTimes);

This could be a hint if the document would be added as DataSource:

Do you have the document included in the XPage as a DataSource? In that case, try to get and update the NotesXspDocument instead of the Document from the DB:

XPage:

<xp:this.data>
    <xp:dominoDocument var="xspDocument"
        action="editDocument"
        documentId="#{param.unid}">
    </xp:dominoDocument>
</xp:this.data>

SSJS code: work directly with the XspDocument

var selectedTimes:java.util.Vector = xspDocument.getItemValue("selectedTimes");
...
xspDocument.replaceItemValue("selectedTimes", selectedTimes);

This could be a hint if the value would not be removed from the document:

In sdtString you are getting a String value:

var sdtString =  getComponent("inputHidden1").getValue();

If you have the time values stored as NotesDateTimes, you will get this type of value inside the Vector and the remove method won't find the String and nothing will be removed.

// In a Vector<NotesDateTime> the String cannot be found:
selectedTimes.remove(sdtString);

Be sure you remove the same type of value you get in the Vector