Refresh to re-control does not work fine after deleting 1 line

I have a field named "selectedTime" in the document, this field stores selected timings added by the user. The add time works perfect. This is the back-end.

I will now explain this problem of picking a date from the front-end. I gave an add button to add times.The custom date-time control is added to re-control when the Add button is clicked. Even if I check the document it displays a list of selected times. Even that works great.

Now if I want to remove the selected time from replay randomly, it removed that particular record from the document, but the last replay record is gone from the page.

I assumed it was a re-control partial update issue, I even tried this but no result. Full refresh breaks the page.

java script code for 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 would be appreciated.

Even if someone has an idea to remove field values ​​for documents, in my case the field name is "selectedTimes" and the values ​​are added once in re-manage, share.

Edit 1:

//Repeat Control

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

      

+3


source to share


1 answer


Another attempt might involve repeating with a viewScope instead of a document:

1) In case of beforeLoadPage / afterLoadPage: get the value from the document and put it in the viewScope variable:

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

      

2) In replay mode, use viewScope:

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

      

3) When the 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 can be a hint if the document is added as a DataSource:

Do you have a document included in the XPage as a data source? In this case, try to get and update 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 XspDocument

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

      


This can be a hint if the value is not removed from the document:

In sdtString, you get a String value:

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

      

If you have time values ​​stored as NotesDateTimes, you will get that value type inside a Vector, and the remove method will not find a String, and nothing will be removed.

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

      

Make sure you are removing the same value type you get in Vector

0


source







All Articles