What are the benefits of using data context in xPages?

I have never used a data context in xPages and would like to know the benefits,

If I want to return something to memory, I often call a function in the SSJS script library, which, it seems to me, is also stored in memory.

so let's say that I have a function in ssjs that returns a notes document, this function can be called from several places on my xpage. the data context will be useful in this case regarding the presence of a function in ssjs scriptlibrary.

+4
source share
2 answers

dataContexts can be thought of as global variables. The benefits of SSJS features are:

1) DataContext launches SSJS / Java / regardless of what the value returns. References to dataContext use EL (for example, # {myVar}), the same as data sources. Therefore, I understand that EL gets the value, and does not run SSJS / Java code every time. Thus, there is a performance advantage.

2) The value of dataContext can be calculated dynamically or on page load. That way you can use $ {javascript: @Today ()} and run it once, rather than run the function every time.

I suspect there is also a performance advantage because links to dataContexts use EL. Therefore, in no links you start SSJS, therefore it does not need to go through the SSJS parser.

An additional advantage of dataContexts is that they can be tied to any level available to data sources - thus XPage, Custom Control or Panel. This gives them an edge over viewScope. Therefore, youo can also set the dataContext in the panel in re-control mode to avoid multiple references to the NotesDocument field or field concatenation.

I tried to avoid storing Domino objects in dataContexts, mainly because of the inherent risks of recycling. I do not know if there is a problem, I

+7
source

@Withers: # {MyVar} I found that it didn’t work when I used the DataContext # {DataStoreDbName} variable in dblookup: (However, I find your posts very valuable by Mr. Withers)

They did not work :

#{DataStoreDbName} @Sum(@DbLookup("#{DataStoreDbName}","personnelbudget",compositeData.catid,10)) #{id:DataStoreDbName} @Sum(@DbLookup("#{id:DataStoreDbName}","personnelbudget",compositeData.catid,10)) 

It worked

I like how the dataContext var is displayed in the DataSources list in the Data section of the Properties tab of the control in which the DataContext was entered.

  • Start by defining a DataContext: var = DataStoreDbName
  • This Data Context variable is an external server database: DB, which I use in @DbLookup.

    Variable name

    " DataStoreDbName is now displayed in the data sources in the data section:

  • This is DbLookup. I am using a DataContext in: @Sum (@DbLookup ( DataStoreDbName , "personnelbudget", compositeData.catid, 10))

enter image description here

  1. The above is an example of another DataConext (obviously), but here is how the variable name was used in calculations in fields or customCoverters of hidden fields (which makes hidden fields look like computed fields in Notes). * Pay attention to @Text () to avoid errors.

enter image description here

The text <xp: text simply displays the value of the DataContext variable, while <xp: inputHidden> uses the value of the DataContext variable in the customCoverter to save / save the value when sending / saving.

+1
source

Source: https://habr.com/ru/post/1398035/


All Articles