Dwr and script session invalidation - dwr

We are using reverse ajax with polling in our DWR 2.0.6 based application. The problem is that when we move away from a page where reverse ajax was set to true, we want that ScriptSession to be invalidated. It does not happen by default.
In the docs for DWR 3.0 it is mentioned that we can call dwr.engine.setNotifyServerOnPageUnload(true); in our js file
But this is not available in 2.0.6.
Any ideas suggestions etc.?

You could write this manually, using an "onbeforeunload" handler.

Related

Refreshing a single portlet in Liferay

I have a problem with refreshing a single Liferay portlet. I wrote a bit of javascript code to refresh a single Liferay portlet every 120s:
function refreshPortlet() {
Liferay.Portlet.refresh("SOME_KEY")
};
setInterval("refreshPortlet()", 120000);
It works fine and the portlet refreshes, but the problem is that content of the portlet does not. I tried to clear the cache of the portlet with WebCachePoolUtil:
function refreshPortlet() {
WebCachePoolUtil.remove("SOME_KEY");
Liferay.Portlet.refresh("SOME_KEY")
};
setInterval("refreshPortlet()", 120000);
But now the function does not execute at all. Any hints?
Thanks in advance,
Stjepko
WebCachePoolUtil is a Java class, thus not available on the JS side. The reason the method is not executing is that it's running into the unavailability of that class.
If you want to execute browser-side code like you did, you'd need to identify where caching is done - e.g. on the browser or on the server. Observe your Developer Tool's network tab and inspect what's going across the wire.
Depending on the portlet that you're trying to refresh - specifically if it's a custom portlet - I'd recommend to implement Ajax explicitly and refresh either from a REST API or through the portlet's serveResource method.

Tiles reloading Left menu using Struts 1.3

I am using struts 1.3 and tiles to develop web application,it is reloading leftmenu even after using tiles.can anyone please give some idea
Tiles won't help you if you want to reload some part of page only as purpose of tiles is to reuse across the presentation tier of an application.
you need to either use frames or dhtml layers to refresh part of a 'page'.
Angular.js is a good option.
If you are using tiles, it is bound to reload the page because tiles only works when the request is sent and the response comes from controller.
The way by which you can avoid reloading of menu in struts 1.x,2 is :-
1. You can use AJAX or a DWR calls to get the response.
2. Or you can use frameset to give the response.

Cakephp 2.x and Jquery Ajax - Cake doesn't think request is ajax

I am working on a little cakePHP application and am trying to AJAX it up a bit with JQuery to make it work a bit nicer for users.
I have just followed this tutorial: Cakephp Jquery AJAX Tutorial but for some reason it isn't working.
One great bit about the tutorial is that functionality falls back to normal CakePHP if the request isn't an AJAX request so my app still works but it doesn't work the AJAX way...
It looks like in my Controller, the request doesn't pass the test:
if($this->request->is('ajax'))
and so continues onto the normal $this->redirect(...) of the non-AJAX way.
Could it be something to do with the if statement for 'ajax'? In the tutorial the author is using a version of cakePHP before 2.0 and so uses $this->RequestHandler->isAjax() but this was deprecated as of cakePHP 2.0.
Thanks for your time.
JsHelper::link might do what you want.
As I think you have discovered, it's nothing to do with Cake. It's because in the tutorial he tells you to make a link, then you are clicking the link to run the action. This causes the AJAX request to fire, but also the actual link gets followed.
You need preventDefault() in your jQuery click event, to stop the browser from following the link in the normal way. This will not affect the link if the user doesn't have JavaScript... because they won't have the click event occur in the first place :)

How to solve Firebug’s “Aborted” messages upon Ajax requests?

I am using Firebug 1.10.2 with Firefox 14.0.1. When showing a web page, the Firebug add-on has this "behavior": Firebug’s “Aborted” message upon Ajax request.
What should I make? Is it so dangerous that I must improve my web application because the presence of some error, or it is a Firebug bug or something else?
Please see the documentation of XHR open() for example here:
https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest
Note: Calling this method an already active request (one for which
open()or openRequest()has already been called) is the equivalent of
calling abort().
Just create a new XHR instance whenever you need one. Better yet, use jQuery or other JS library to do AJAX. It should shield you from these intricacies.
I saw this problem when trying to load a JavaScript file using HTTPS, but was serving the site on my local development environment using HTTP. The request to fetch the JavaScript file would fail with the Aborted message in FireBug. Making the requests use the same protocol worked for me.

Integrating jQuery with Struts2.0.9

How can I integrating jQuery with Struts 2.0.9? Here I can not upgrade my Struts2 version. I want to leverage jQuery ajax functionality with Struts2. Not able to figure out how can I pass a valuestack object to jQuery.
I guess you can use either struts2-jquery-plugin
Struts2 does not care of you call its action by Normal page submit or by ajax calling using Jquery or any other javascript framework
Once you call you action value-stack and other critical parameters of Struts2 will be available at your disposal.
Still your question is not clear what is your requirements, more details can pour more valuable inputs
Though the question has been answered, there are some significant issues when we speak about struts2 jQuery plugin 2.5.0.
It is based on jQuery 1.4 which is outdated, multiple issues have been closed from 1.4 to 1.7
Multiple browser support issues especially with IE (if you want to have browser compatibility).
I found it much more easy to directly use jQuery with Struts2. As mentioned, calling via Ajax or non ajax has doesnt make any difference to Struts2 framework, request is handled in the same way.
If you want to use Struts2 jQuery Plugin you can either work on the source code and upgrade the jQuery to 1.7 and accordingly change newer API.

Resources