Action class called twice from IE and not firefox - java

I have an application where an absolutely normal link (like below).. when clicked, calls the action class twice. And this behaviour happens only in IE. In Firefox, when i click on the same link, it calls the action class only once.
Load
This is an older application and im using Struts 1.3 and Tiles.
Any idea why this is happening and/or how it can be troubleshooted?

It could be that IE is preloading prefetching the link.
To verify this, log the time when the request is received. Load the page, wait ~10 seconds, and click the link. If the difference between the log entries is ~10 seconds, it's a prefetch.
The idea is the browser preloads links the user is likely to click, so the result can be server immediately form the browser cache.
HTML5 makes this explicit by defining rel="prefetch". This attribute and value can be set on a, area, and link tags.
Check your page for <link rel="prefetch" href="url" /> or <link rel="next" href="url" /> in the HEAD element. Also, check your A tags for rel attributed as well.
MicroSoft claims to officially support this in IE 11.
All of this is intended to make pages appear more responsive to the user. Where this can fall apart is when the page being retrieved is not cacheable. This will cause the page to be fetched again when the user clicks it. This can be improved by taking steps to make sure the result cacheable. Set appropriate cache headers. There is a Private cache control for content that is intended for a single recipient. It's only stored in private caches, typically the user's browser.
Additionally, your page may not be considered cacheable if it does not provide a Content-length header.

Related

XPages: beforePageLoad runs more than once... Why?

We have this XPages application that has one master page (say M.xsp) and several sub-pages, all in separate iframes on the master page (loaded as A.xsp, B.xsp and C.xsp in separate tabs). The application runs fine, generally speaking. Each sub-page shouldn't interfere with the other pages, and as far as I know, it doesn't. Some page-dependent data is stored in viewScope variables, but for the most important parts we developed Managed Beans, with their data mostly in view-scope too.
Now, what we see is the following:
on page A, we do several clicks and some AJAX calls occur to fetch data from the server
we switch to page B, we do 3 AJAX requests for data to the server
we switch back to page A, we do one click to fetch some data again, and a beforePageLoad event occurs! Needless to say, the page is still loaded.
on the same page A, we do a new click to fetch different data, and beforePageLoad is triggered again!
viewScope is lost, my page-dependent bean is lost, very strange.
We checked, but changing the amount of memory dedicated to XPages didn't change anything.
XPages 9.0.1, browser-only.
Can someone please explain this behaviour: how come beforePageLoad is repeatedly executed? How can we prevent it?
Thanks!!
Twas indeed related to the max number of pages in memory. Every time an item in a list on page B was clicked, a sub-page (B1) was loaded in yet another iframe, using a URL with the item as parameter. Many clicks in the list forced many pages to load, causing all other pages disappear from memory. So when we moved back to page A and triggered some partial refresh there, it was as if the the page was new to the runtime environment.
I rewrote the sub-page B2 to stay in memory, and do a partial refresh itself when the list value changes. Quite a lot faster, and no unnecessary page drops.

How to do multiple page form submission with ajax request

The application is to ship items where on 1st page customer fills up information. Then on 2nd page he gets different rate options to choose from. Then on 3rd page he needs to fill up address info. Then on 4th page payment info & so on.
Now let's say customer enter details on the 1st page. I send ajax request to server & get different rates options.
Once I come back in ajax success, I need to change the page to 2nd jsp. Once customer chooses rate options then again make ajax request & get 3rd jsp & so on.
I need to implement UI side of the code without reloading or redirecting the page. Also from 2nd & 3rd jsps I should have a back button to go to the previous page.
Is it possible with only jquery like setting/replacing divs or is there any plugin I could use like twitter bootstrap carousel?
I need some help in ajax success function so that I can go to next or prev jsps with submit & back buttons?
I am using spring MVC framework.
I think you are a bit confused about who makes what: you are mixing jsp and ajax, server side computation and client side.
Don't care about jsp or spring. They have nothing to do with what you need: you are going to implement a single page application, so jsp and spring will only be in charge of deliver datas to the client, for example, in the form of json (to bind to a template, see jsview) or html (to append a dom element).
Customer enter details on the 1st page, on submit, an ajax call happens. The response of the call will be, as I said above, json or html that will be bind to your document, so now you can show the new data and hide the old one, with bootstrap carousel is ok... and so on for the other pages.
For the back button, if you use only html5 browser you should manipulate the browser history (https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history), if not you should use a polyfill like history.js (https://github.com/browserstate/history.js/)
This response is only a clue of a way to do what you need. AngluarJS or ember.js are another keyword you can use to search solutions to your problem.

GWT/GXT adding nocache.js file, in the header or after the body?

I notice that most GXT/GWT applications put the nocache.js file after the body tag. And few seem to put in the include in the header tag. Why is that?
Given the fact that the GWT script tag will be evaluated synchronously (the tag), but fetched asynchronously (the code, into an iframe), I don't see why not put it as the very first thing. Time saved!
Unless, you have some kind of complex logic that cannot have the chance to be properly displayed before the onModuleLoad() call (e.g., images evaluated but still not fetched), much like Steffen Schäfer pointed out. But you can defer you app startup for them though.
For more info, have a look here.
From my point of view there are 2 cases:
If you use GWT to only enhance your page that is generated on the server side then put the <script> at the end. That allows your browser to render the initial content of the page before parsing the JS code.
If you built a single page application that is completely generated by GWT on the client side, there's no content to be initially shown. In that case you can put the <script> to the head.
Be aware that 1. also applies if you implemented a loading animation or placeholder content to be initially shown.

Closing popups on session expiry

Here is the thing : my webapp has loads of popups and my boss wants 'em closed on session expiry, coz when session expires and an user presses refresh on a popup, he is being shown the logon page -> user logs on -> user is directed to the dashboard. Now, a dashboard screen in a popup is totally uncool. Here is where google got me:
Have javascript to close popup onload. Generate this onload script into the response if session has expired (checking session expiry from jsp and including onload script conditionally).
Do you think this is a good way to it? What is the best practice for this scenario?
P.S: I am not allowed to use AJAX
In a past life, I made a popup manager object that maintained what windows were open. You should probably make one of these if not already done. Then, you can use setTimeout to call a function after so many minutes (or whatever time you want) have gone by. This will check for recent activity (probably via AJAX) and close the popup if you determine that the session has expired. If not, call setTimeout again with your new time, properly adjusted for most recent activity.
^^before the AJAX edit.
Well, since you can't use AJAX, can you put something in the url that will tell you it's a popup? Then you'll know not to show the login screen when the user hits reload.
The best way would be an XMLHTTP request to check login and close them if required - do this periodically.
Astute readers (meaning everyone) will notice that this is an AJAX request, but if you phrase it that way it might get accepted as whoever dictated that you 'aren't allowed to use AJAX' is clearly an idiot.
An alternative way to implement modal dialogs in a web application is to:
Model the dialog in a DIV, default styled to display: none;
On desired action, inject/append the Modal dialog DIV into the page source
Reset the CSS display so the modal dialog DIV is visible, overlaid on top of the page by setting the CSS z-index property
Make the modal dialog disappear upon either successful execution or the user cancelling out
Because the modal dialog is part of the page source, the dialog will disappear when the session times out. This approach doesn't spawn supporting windows that can be orphaned as the poster is attempting to address. And it fits the requirement of not using AJAX.
You can code these by hand, but I don't really recommend it because of having to support various browser. I suggest looking at the Yahoo User Interface. You can tailor it to suit your needs (IE: only modal dialogs), and it would support AJAX if requirements change down the road.
Beware of spawning modal dialogs from modal dialogs.
If your boss is asking you to achieve this, without using AJAX, then you're in trouble. He should understand that the only connection a browser has to the server (without refreshing the page) is javascript (what he understands to be ajax).
The best way to do this is to setup a script on the pages to ask the server if the user is still logged in every 30 seconds or so.
setInterval(function(){
$.get("loggedin.php", function(result) {
if (!result.isLoggedIn)
window.close();
});
}, 30000);
This script assumes you're using the jQuery framework for rapid development of javascript solutions. This also uses JSON (Javascript Object-notation) to test a return-value from the loggedin.php file.
Bottom line, you need to use AJAX. Tell your boss there is no other way. If he still doesn't get it, ask him to balance his checkbook without using math.
In theory, you could avoid AJAX by using a hidden flash widget...
But more practically, AJAX is the 'right' solution, and I think you will have to talk to your boss, determine where this 'no AJAX' rule came from, and convince him that AJAX is the best way to solve this problem.
Does he think AJAX would be take too much time to implement? If so, you should prove him wrong. Does he think it will be hard to maintain? If so, show how simple the code to do this will be, and how widely used the common AJAX libraries are. If your boss is reasonable, then his goal is to what is best for the product, and you should be able to reason with him.

Problem in Wicket

I have a page by name BranchMap that uses GoogleMap to show some building to user after he has logged in.
the data was at first in protected(password required) situation (in CategoiresXML which extends ProtectedPage) but i found that google can't log in the system and make the page extended from WebPage.
But now when I go to BranchMap page and Press CTRL+F5 the page expires and i refered to HomePage.
Does anyone know the reason? if you want more info tell me to put them.
Not entirely sure what you're describing - it's not quite clear, but see if this helps:
This can happen when some Ajax call causes the page to change, but refreshing the page (which isn't bookmarkable) who's urls refers to the expired version causes this exception. I had this problem at one point when we had multiple iframes calling into our wicket app (sorry for the fuzzy explanation - it was a while ago).
In the end, for our application, we had to split the different iframe sources into different servlets within web.xml - in order to completely isolate the sessions of the different pages - but that's another story.
Try adding this to your wicket application init method.
// debug code for fixing session issue (multiple ajax using pages inside
// one browser)
get().getPageSettings().setAutomaticMultiWindowSupport(true);
And check out the documentation here: https://ci.apache.org/projects/wicket/apidocs/1.4.x/org/apache/wicket/jmx/PageSettings.html#getAutomaticMultiWindowSupport()
Can you show the stack trace?
What version of Wicket are you using?
There was a bit of a miss-communication in the javadoc prior to 1.4-rc3 as well, patched here:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/IPageSettings.java?r1=647167&r2=768578&pathrev=768578&diff_format=h
The issue here: https://issues.apache.org/jira/browse/WICKET-2233
Here is the updated comment in the javadoc from IPageSettings:
/**
* Gets whether Wicket should try to support opening multiple windows for the same session
* transparently. If this is true - the default setting -, Wicket tries to detect whether a new
* window was opened by a user (e.g. in Internet Explorer by pressing ctrl+n or ctrl+click on a
* link), and if it detects that, it creates a new page map for that window on the fly. As a
* page map represents the 'history' of one window, each window will then have their own
* history. If two windows would share the same page map, the non-bookmarkable links on one
* window could refer to stale state after working a while in the other window.
* <p>
* <strong> Currently, Wicket trying to do this is a best effort that is not completely fail
* safe. When the client does not support cookies, support gets tricky and incomplete. See
* {#link WebPage}'s internals for the implementation. </strong>
* </p>
*
* #return Whether Wicket should try to support multiple windows transparently
*/
boolean getAutomaticMultiWindowSupport();

Categories

Resources