在xPages中使用数据上下文有什么好处? [英] what's the benefits of using data context in xPages?

查看:65
本文介绍了在xPages中使用数据上下文有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从未在xPages中使用过数据上下文,想知道它的好处,



如果我想返回内存中的内容,我经常在SSJS脚本库中调用函数



因此,假设我在ssjs中有一个函数返回了notesdocument,该函数可能会在我的xpage中的多个地方调用。

解决方案

dataContexts可以被认为是在ssjs脚本库中具有某种功能。全局变量。相对于SSJS函数的优点是:



1)dataContext运行SSJS / Java /无论返回什么值。对dataContext的引用使用EL(例如#{myVar}),与数据源相同。因此,我的理解是EL获得了价值,而不是每次都运行SSJS / Java代码。这样就可以提高性能。



2)dataContext的值可以动态计算或在页面加载时计算。因此,您可以使用$ {javascript:@Today()}并运行一次,而不是每次都运行一个函数。



我怀疑这样做还有性能优势,因为引用dataContext使用EL。因此,在参考中的任何时候都不需要运行SSJS,因此不必通过SSJS解析器。



dataContexts的其他好处是它们可以在任何范围内进行范围划分。数据源的级别-XPage,自定义控件或面板。这给了他们优于viewScope的优势。因此,您还可以在重复控件的面板中设置dataContext,以避免对NotesDocument的字段或字段的多个引用。



我倾向于避免存储DataContext中的Domino对象,主要是因为存在回收的固有风险。我不知道是否有问题,我是

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

If I want to return something in memory I often call function in a SSJS scriptlibrary which I believe is also stored in memory.

so let's say I have a function in ssjs that returns a notesdocument, this function might be called from several places in my xpage. will data context be benefitial in this case in regrards to having a function in a ssjs scriptlibrary.

解决方案

dataContexts can be thought of as global variables. The advantages over SSJS functions are:

1) The dataContext runs the SSJS / Java / whatever are returns the value. References to the dataContext use EL (e.g. #{myVar}), the same as datasources. So my understanding is that the EL gets the value, rather than running the SSJS / Java code each time. So there's a performance benefit there.

2) The dataContext's value can be computed dynamically or on page load. So you can use ${javascript:@Today()} and run it once rather than running a function each time.

I suspect there's also a performance benefit because references to dataContexts use EL. So at no point in the references do you run SSJS, so it's not having to go through the SSJS parser.

The additional benefit of dataContexts is they can be scoped to any level that datasources can - so XPage, Custom Control or Panel. This gives them an advantage over viewScope. So youo can also set a dataContext in a panel in a repeat control, to avoid multiple references to a NotesDocument's field or concatenation of fields.

I've tended to avoid storing Domino objects in dataContexts, mainly because of the inherent risks of recycling. I don't know if there's an issue, I'

这篇关于在xPages中使用数据上下文有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆