如何确保 Liferay/ICEFaces 中的每次回发后都会调用 Javascript 函数?

发布于 2024-10-30 20:55:11 字数 432 浏览 1 评论 0原文

我对 Liferay 和 ICEFaces 的经验很少。我需要构建一个 portlet,在每次回发发生时调用特定的 Javascript 函数。

事实上,当通过 AJAX 提交表单时,会出现加载屏幕并阻塞屏幕。当回发完成后,我需要将其取出并再次将控制权交给用户。

我尝试将

问题是,当服务器不更改 HTML 时(即,搜索没有返回结果,您再次搜索,仍然没有结果),该函数不会再次执行。

即使我可以发布一些代码,我对构建 Web 应用程序的架构也知之甚少。我在这里提供的是我所掌握的所有信息。通过编辑 javascript 函数以在调用时发出警报,我发现了页面的行为。

你能帮我吗?

I have very little experience with Liferay and ICEFaces. I need to build a portlet that calls a specific Javascript function every time a postback occurs.

In fact, when the form is submitted through AJAX, a loading screen appears and blocks the screen. When the postback completes, I need to take it out and give control to user again.

I have tried to put the <script> snippet in the portlet's body and it succeeds in executing when the page is first loaded (it's ok) and also when a postback changes the page's HTML content.

The problem is, when the server doesn't change the HTML (ie. a search returned with no result, you search again and you still get no results) the function is not executed again.

Even if I could post some code, I have very little idea of the architecture the web application is built on. What I gave here is all the information I have. By editing the javascript function to emit alerts when it's called I found the behaviour of the page.

Can you help me with that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌生 2024-11-06 20:55:11

您是否尝试过以下方法:

<script>
    Ice.onSendReceive('document:body',
        function(){/*Before send ajax request*/},
        function(){/*After receive the response*/}
    );
</script>

但是此解决方案适用于您发出的每个ajax请求,希望这可以帮助您。

Have you tried the following:

<script>
    Ice.onSendReceive('document:body',
        function(){/*Before send ajax request*/},
        function(){/*After receive the response*/}
    );
</script>

But this solution applied for every ajax request you made, hope this can help you.

谈下烟灰 2024-11-06 20:55:11

我用一个奇怪的技巧和我想分享的随机数来制作它。

首先,在支持 bean 属性中,我创建了一个方法

public String getLoadFunction()
{
    return "functionName("+ new Random().nextDouble() +");";
}

,然后

<script>
    #{MyViewBean.loadFunction}
</script>

“简单地”,ICEFaces 非常智能,它会在处理 AJAX 请求时检查 HTML 是否已被修改。此技巧与将随机数附加到 HTTP URL 以避免缓存非常相似。

I made it using a weird trick with random numbers I want to share.

First, in the backing bean property I created a method

public String getLoadFunction()
{
    return "functionName("+ new Random().nextDouble() +");";
}

and then

<script>
    #{MyViewBean.loadFunction}
</script>

"Simply", ICEFaces is so smart it checks if the HTML has been modified or not when processing AJAX requests. This trick is very similar to appending a random number to HTTP URLs to avoid caches.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文