我可以将 xPage 上的某些控件的加载延迟到页面加载之后吗
是否可以延迟加载 xpage 上的某些控件?
这就是问题所在:假设您有一个控件执行全文搜索并在重复控件中显示结果。此 ft 搜索可能需要很长时间,并且会使网页加载处于等待状态,直到搜索结果准备就绪。
我希望我的页面最初加载大部分数据,并且一些“耗时”的控件应该在初始加载后作为单独的请求加载到页面中。
这样,用户将立即看到网页,但页面上的某些数据将稍后加载,而不会使网页处于等待服务器的状态。
可能的?
is it possible to delay loading of some controls on an xpage?
This is the problem: let's say you have a control that does a fultextsearch and displays the result in a repeat control. this ft search might take a long time and will hold the webpage loading in a waiting state until the search result is ready.
I want my page to load most of the data initally, and some "time consuming" controls should be loaded in to the page as a sperate request after the inital load.
this way the user will immediatly see the webpage, but some of the data on the page will load a little bit later without holding the webpage in a waiting state from the server.
possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用渲染的缺点是,即使相应的标记未发送到页面,所有值绑定仍将计算。因此,这里的技巧是确保组件在您需要时根本不存在。
每个组件都有一个 getChildren() 方法。这会返回一个可变的组件列表,其中有一个 add() 方法。这允许您在页面加载时或稍后在事件期间将组件动态添加到页面。出于您尝试执行的操作的目的,您可能希望推迟添加“昂贵”组件,直到后续事件发生。
创建一个直接附加到视图根()的事件处理程序,给它一个唯一的ID(例如“loadExppressiveComponentsEvent”,将其刷新模式设置为部分,将刷新ID设置为将包含搜索结果的任何div或面板,并设置其事件名称为任意事件(例如“loadExpectiveComponents”),这可以防止您的事件被实际用户行为触发,
然后将事件的代码设置为将注入您的组件的脚本块()以在页面后面触发该事件 。已加载:
XSP.addOnLoad(函数(){
XSP.firePartial(null, "#{id:loadExpectiveComponentsEvent}");
});
您的页面将在没有搜索结果组件的情况下加载。一旦页面完全加载,就会自动触发组件注入事件。
有关如何对注入事件进行编码的指导,请打开从现有页面生成的 Java 文件,以查看需要注入哪些组件以及将其值设置为什么。
The downside to using rendered is that all the value bindings will still evaluate, even if the corresponding markup isn't sent to the page. So the trick here is making sure the components don't even exist until you want them to.
Every component has a getChildren() method. This returns a mutable List of components, which has a add() method. This allows you to add components to the page on the fly, either while the page is loading, or later during an event. For the purposes of what you're trying to do, you would want to defer adding the "expensive" components until a subsequent event.
Create an event handler attached directly to the view root (), give it a unique ID (e.g. "loadExpensiveComponentsEvent", set its refresh mode to partial, set a refresh ID to whatever div or panel will contain the search results, and set its event name to an arbitrary event (e.g. "loadExpensiveComponents"). This prevents your event from being triggered by actual user behavior. Set the event's code to SSJS that will inject your components.
Then add a script block () to trigger the event after the page has loaded:
XSP.addOnLoad(function(){
XSP.firePartial(null, "#{id:loadExpensiveComponentsEvent}");
});
Your page will load without the search result components. Once the page has fully loaded, it will trigger the component injection event automatically.
For guidance on how to code the injection event, open the Java file that has been generated from your existing page to see what components need to be injected and what to set their values to.
您可以将它们打包到面板中并将其渲染状态设置为rendered=#{viewScope.pageFullyLoaded}。然后在onLoad事件中有一个XSP。您设置 viewScope.pageFullyLoaded=true 的partialRefresh 请求
有点丑但是可行。现在您可以将该代码包装到您自己的自定义控件中,这样您就可以拥有“lazyGrid”、“lazyPanel”等。
You can pack them into a panel and set their rendered status to rendered=#{viewScope.pageFullyLoaded}. Then in the onLoad event have a XSP. partialRefresh request where you set viewScope.pageFullyLoaded=true
A little ugly but doable. Now you can wrap that code into your own custom control, so you could have a "lazyGrid", "lazyPanel" etc.
不知道为什么我之前没有想到这一点。 extlib中的动态内容控制实际上解决了这个问题。页面加载后,可以使用 javascript 和 ssjs 在 ClientLoad 上触发 dcc。
我现在面临的一个问题是我已经在我的网站上使用了 dcc,因此我需要在我的 dcc 中放置另一个 dcc。这似乎有点问题。我已将其报告给 openNTF 上的 extlib 团队。
Not sure why I did not think of this before. the dynamic content control in extlib actually solves this problem. the dcc can be triggered onClientLoad both using javascript and ssjs afer the page has loaded.
one problem I am facing now is that I am already using the dcc on my site so I need to put another dcc within my dcc. and this seem to be a bit buggy. I have reported it to the extlib team on openNTF.