问题
We have to achieve some task consisting in some calculations ( recursive calculations ) based on some fields values inside the doc. Let say, for example, creating some invoices.
IN some old classic lotus notes applications, we just created a table with 24 rows and 4 columns, in every cell being an editable / computed field. You can imagine what kind of formulas we entered in each field, considering the fact that the current fields row were based on the value of the previous fields row and so on.
In xpages, my scenario was to create a button which shows a dialog where the invoice structure is. Completing all the fields and then save/hide the dialog, the doc. < invoice > will be listed on an (embedded) view inside the main document. the current opened dialog / invoice will take consideration on the previous invoice values. Obviously, there would be some disadvantages, the first I noticed was: let say my view lists 5 invoices. If I open for editing the 2nd one, I modify some field => from the 3rd to the last one, will be all be changing on this last edit?
Is there any sample snippet from I could get inspired or a simple module of this type ofcalculations?
I would like some advices and some helpful tips/suggestions. Also, I will appreciate any important considerations that I should be beware of.
回答1:
This is a prime example of where XPages and a repeat control is of benefit.
On the old Notes form, you'd have added 24 rows of 4 columns. Think of the overhead involved if someone then needs to create 25 invoices, or the calculation/hide-when is wrong for one column, or another column is required.
Repeat controls allow you to build one instance of the layout and iterate over 2, 20, 200 rows dynamically. You can use a dialog, or make a row editable/non-editable by having a button that adds the relevant key (a UNID for a document, a key if you're building a Map of Java objects) to a scoped variable; then the fields are editable if the viewScope variable is the key for the current row, otherwise not.
Adding additional rows is simple - change the rows value or add a page. Adding an additional column is easy - do it once and it's done for all. There are no hide-when formulas for each row, so no chance of mistakes there. Calculations point to the data for that row, not a field with "_1", "_2", "_3" etc. If a calculation needs changing, do it once and it's done for all rows.
回答2:
The code you need is in Exercise 23 of the intro to XPages workshop. You might want to review it here: http://www-10.lotus.com/ldd/ddwiki.nsf/m_Home.xsp?documentId=C8E56F876AF2315A852575F60076592B#mobileViewer
I wrote it
回答3:
In our own instance of this, we have requisitions, purchase orders and payment requests. Each of those is a document and each line item on each of those documents is ALSO a document. Then, the repeat on the main document (invoice in your case) references the view, using a filter so that it only gets the line items for that invoice. Thus, you can edit the line items on the invoice (include edit, save and cancel buttons on each entry in the repeat control) and save them.
Here's the skeleton of a viewEntryCollection used to make line items available in a panel inside a repeat.
<xp:repeat id="repeat1" rows="1000" var="lineItem" indexVar="itemIndex">
<xp:this.value><![CDATA[#{javascript:var ludb:NotesDatabase = getDb("tamisDb");
var luview:NotesView = ludb.getView("LULineItemsByParentDocID");
var parentDocID = compositeData.parentDocID;
if (parentDocID == null) { parentDocID = "0" };
var vec:NotesViewEntryCollection = luview.getAllEntriesByKey(parentDocID, true);
if (vec.getCount() == 0){
viewScope.totalProcValue = 0;
}
return vec;}]]></xp:this.value>
<xp:panel id="lineItemDataPanel">
<xp:this.data>
<xp:dominoDocument var="itemDoc" formName="LineItem"
action="openDocument" documentId="#{javascript:lineItem.getUniversalID()}"
ignoreRequestParams="true">
<xp:this.databaseName><![CDATA[#{javascript:getDb("tamisDb")}]]></xp:this.databaseName>
</xp:dominoDocument>
</xp:this.data>
To bind a control to the line item document, use the var in the source document.
<xp:inputText value="#{itemDoc.Description}" id="lineItemEditDescription" style="width:200.0px">
</xp:inputText>
So, 'lineitem' from the var value of the repeat is a NotesViewEntry object (lineitem) used by that dominoDocument definition to create a NotesDocument data source, which we refer to by the var on it's definition (itemdoc). Does that make sense? I might not have needed the second layer of abstraction, but that's how the code was passed to me.
来源:https://stackoverflow.com/questions/25779853/xpages-how-to-obtain-create-this-calculations-module