I’ve got the following jsp page and I’m using struts2-jquery-plugin-3.1.1
<script type="text/javascript">
function openDialog() {
$.publish('openDialog');
}
</script>
</head>
<body>
<div id="detailContainer">
<div id="header">
<s:action name="ecu-info-header" var="dc"/>
<ul class="vMenu">
<s:iterator var="ecus" value="ecuList" status="status">
<s:url id="ecu" value="ecu-info-detail" escapeAmp="false">
<s:param name="id" value="%{id}"></s:param>
<s:param name="ecuName" value="name"></s:param>
<s:param name="ajax" value="true"></s:param>
</s:url>
<li class="vMenuItem"><sj:a href="%{ecu}" requestType="GET" targets="detail" onclick="openDialog()" onCompleteTopics="closeDialog"><div class="vMenuItemText"><s:property value="description"/></div></sj:a></li>
</s:iterator>
</ul>
</div>
<div id="detail">
</div>
</div>
<div id="clear"></div>
<s:submit cssClass="vMenuItemText hidden" id="submit" type="button"
label="Back" name="back"/>
<sj:dialog
id="myclickdialog"
autoOpen="false"
modal="true"
title="Please Wait ..... "
closeOnEscape="false"
openTopics="openDialog"
closeTopics="closeDialog"
overlayOpacity="0.85"
showEffect="scale"
>
<p class="instruction">Reading data from the vehicle</p><br /><br />
<img id="loading" src="<%=request.getContextPath()%>/resources/images/loading.gif"/>
</sj:dialog>
</body>
The first time I click on one of the links, the dialog box opens and closes as expected with the results loaded in div id=”details”. Second and subsequent clicks on any of the links results in the fresh data reloading, but the dialog box never re-opens.
EDIT:
I’ve taken the sugestions below and tried to convert to pure JQuery and I still have the same problem.
<script type="text/javascript">
$(document).ready(function() {
$('#popup').dialog({ autoOpen: false })
$('#popup').dialog({ modal: true }) // set modal
$('#popup').dialog({ closeOnEscape: false }); // prevent closing by pressing the escape key
$('#popup').dialog({ dialogClass: 'no-close' }); // in conjunction with css hides the "x" to close button
$('#popup').dialog({ title: 'Please wait ....'});
$('.anchor').each(function() {
$(this).click(function() {
processDialog($(this).attr('href'));
return false;
});
});
});
function openDialog() {
$('#popup').dialog('open');
}
function processDialog(url) {
openDialog();
$.get(url, function(data) {
$('#popup').dialog('close');
$('#detail').html(data);
});
return false;
}
</script>
</head>
<body>
<div id="detailContainer">
<div id="header">
<s:action name="ecu-info-header" var="dc"/>
<ul class="vMenu">
<s:iterator var="ecus" value="ecuList" status="status">
<s:url id="ecu" value="ecu-info-detail">
<s:param name="id" value="%{id}"></s:param>
<s:param name="ecuName" value="name"></s:param>
<s:param name="ajax" value="true"></s:param>
</s:url>
<li class="vMenuItem"><s:a cssClass="anchor" href="%{ecu}"><div class="vMenuItemText"><s:property value="description"/></div></s:a></li>
</s:iterator>
</ul>
</div>
<div id="detail">
</div>
</div>
<div id="clear"></div>
<s:a cssClass="vMenuItemText" id="floatingButton" href="display-diagnostic-menu">Back</s:a>
<div id="popup" class="hidden">
<p class="instruction">Reading data from the vehicle</p><br /><br />
<img id="loading" src="<%=request.getContextPath()%>/resources/images/loading.gif" />
</div>
First link I click on, the dialog opens as expected, the get request executes, the dialog closes and the data is refreshed. Any subsequent attempt to click on one of the links results in Firebug console reporting “(#popup).dialog is not a function”. Refreshing the page and everything starts to work, but again, only once.
EDIT
I found the blog entry at http://blog.nemikor.com/2009/04/08/basic-usage-of-the-jquery-ui-dialog and as a result the answer seems to be to remove the div for the dialog from my jsp page and create it javascript when the dialog is initialised. So what I’ve got now is
<script type="text/javascript">
var $dialog;
$(document).ready(function() {
$dialog = $('<div></div>')
.html('<p class="instruction">Reading data from the vehicle</p><br /><br /><img id="loading" src="<%=request.getContextPath()%>/resources/images/loading.gif"/>')
.dialog({ autoOpen: false,
modal: true, // set modal
closeOnEscape: false, // prevent closing by pressing the escape key
dialogClass: 'no-close', // in conjunction with css hides the "x" to close button
title: 'Please wait ....'
});
$('.anchor').each(function() {
$(this).click(function() {
processDialog($(this).attr('href'));
return false;
});
});
});
function processDialog(url) {
$dialog.dialog('open');
$('#detail').empty();
$.get(url, function(data) {
$('#detail').html(data);
$dialog.dialog('close');
});
return false;
}
</script>
</head>
<body>
<div id="detailContainer">
<div id="header">
<s:action name="ecu-info-header" var="dc"/>
<ul class="vMenu">
<s:iterator var="ecus" value="ecuList" status="status">
<s:url id="ecu" value="ecu-info-detail">
<s:param name="id" value="%{id}"></s:param>
<s:param name="ecuName" value="name"></s:param>
<s:param name="ajax" value="true"></s:param>
</s:url>
<li class="vMenuItem"><s:a cssClass="anchor" href="%{ecu}"><div class="vMenuItemText"><s:property value="description"/></div></s:a></li>
</s:iterator>
</ul>
</div>
<div id="detail">
</div>
</div>
<div id="clear"></div>
<s:a cssClass="vMenuItemText" id="floatingButton" href="display-diagnostic-menu">Back</s:a>
</body>
Why this works instead of referencing a div in the jsp page I have no idea and
would be grateful for an explanation.
Have you looked in the browser debug console?
similar bug: http://code.google.com/p/struts2-jquery/issues/detail?id=652
I recommend using the javascript and jQuery instead struts2-jquery-plugin. It is more flexible and clear.