Hello again everyone,
I guess I would like to give an update on my struts 2 and ajax integration.
I appreciate everyone's responses as they have helped a lot to resolve my
problem with ajax and the back button. My seemingly last problem I have has
to do with IE (no surprise).
I have implemented some javascript state object that uses the prototype.back
function to handle the back button. I also add that state object to the
dojo.undo.browser.addToHistory. To give an idea of the test javascript
functions I use they are:
<%@ page language="java" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<script language="JavaScript" type="text/javascript">
// Dojo configuration
//djConfig = { isDebug: true, debugAtAllCosts: true,
preventBackButtonFix:
false };
djConfig = { isDebug: true, preventBackButtonFix: false };
</script>
<s:head theme="ajax"/>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.lang.common");
dojo.require("dojo.undo.browser");
dojo.require("dojo.io.*");
//dojo.hostenv.writeIncludes();
var data = {
link0: 'This is the initial state (page first loaded)',
link1: 'This is data for link 1',
link2: 'This is data for link 2',
link3: 'This is data for link 3',
link4: 'This is data for link 4',
link5: 'This is data for link 5',
link6: 'This is data for link 6',
link7: 'This is data for link 7'
};
var HistoryTracker = function(id){
this._id = id;
//TODO: commenting this out breaks FF 1.5. Others?
Can't seem to find
iframe id/name?
this.changeUrl = shouldChangeUrl();
}
HistoryTracker.prototype.back = function(){
updateOutput('BACK for id: ' + this._id);
showDataForId(this._id);
}
HistoryTracker.prototype.forward = function(){
updateOutput('FORWARD for id: ' + this._id);
showDataForId(this._id);
}
createXhrHistoryTracker = function(url){
var request = new dojo.io.Request(url, 'text/xml', null,
shouldChangeUrl());
dojo.lang.mixin(request, {
data: null,
load: function(type, evaldObj){
if(type == "load"){
this.data =
evaldObj.getElementsByTagName('data')[0].childNodes[0].nodeValue;
//evaldObj.getElementsByTagName('data')[0].text;//.getElementsByTagName('data')[0];
updateDataDisplay(this.data);
}
},
back: function(){
updateOutput('XHR BACK for URL: ' +
this.url);
updateDataDisplay(this.data);
},
forward: function(){
updateOutput('XHR FORWARD for URL: ' +
this.url);
updateDataDisplay(this.data);
}
});
return request;
}
function goIoBind(url){
dojo.io.bind(createXhrHistoryTracker(url));
}
function goNav(id){
showDataForId(id);
var historyTracker = new HistoryTracker(id);
dojo.undo.browser.addToHistory(historyTracker);
}
function shouldChangeUrl(){
return
document.getElementById('changeUrlCheckbox').checked;
}
function showDataForId(id){
updateDataDisplay(data[id]);
}
function updateDataDisplay(dataString){
document.getElementById('dataOutput').innerHTML =
dataString;
}
function updateOutput(message){
document.getElementById('output').innerHTML += message
+ '<br />';
}
dojo.addOnLoad(function(){
dojo.undo.browser.setInitialState(new
HistoryTracker('link0'));
});
</script>
At this point, I can make it work fine for FF version <= 3.0. When I try to
use IE 6.0 and 7.0 there is the problem. When I press on the buttons the
back button does not notice there has been a change in state. This only
applies to when I import struts 2.0.11's dojo.js (head theme="ajax"). When
I directly include the v 0.4.3 dojo.js it works fine on IE.
Since this works for FF using strut's dojo.js I am curious to why it would
not work with IE.
In short when I press a button on IE no state changes, however the state
does change on FF. So on IE if there is a back available it is the back
state of the most recent page I was not on, and does not render any ajax
states.
I hope this makes sense and thank you all for the help
--
View this message in context:
http://www.nabble.com/Struts-2-%2B-Ajax-and-Back-Button-tp18200250p18318876.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]