This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes Image while loading a page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Image while loading a page" Watch "Image while loading a page" New topic
Author

Image while loading a page

surya naidu
Ranch Hand

Joined: Jul 26, 2010
Posts: 32
Hi

I am using Struts 1.2

I want to generate a GIF on a page to say sth is loading

The original scenario is i have a page which on submit opens a popup and displays data.But the data takes a lot of time to come on the page
So in the mean while i want to show a GIF on the popup to show its loading

Please help
surya naidu
Ranch Hand

Joined: Jul 26, 2010
Posts: 32
Can someone suggest me any possible solutions please
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

In struts 2 we can achieve that using waitAndExecute interceptor. Figure out how to do it struts 1.2.


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
surya naidu
Ranch Hand

Joined: Jul 26, 2010
Posts: 32
Any suggestions for Struts1.2 please
seshu Palamanti
Ranch Hand

Joined: Jul 03, 2004
Posts: 59
I had a similar problem and was able to do using a this way and it works



function gowait() {
document.getElementById("main").style.visibility="hidden";
document.getElementById("wait").style.visibility="visible";
window.setTimeout('showProgress()', 500);
}
function showProgress(){
var wg = document.getElementById("progressbar");
wg.src=wg.src;
}


<html:form action="/yourAction.do" onsubmit="gowait();">

<div id="main">
your contents that will wait
</div>

<div id="wait" style="visibility:hidden; position: float; top: 0; left: 0">
<div id="center250b">

<div id="fixedtop2">
<table >
<tr><td ><font color = #FFFFFF face ="Garamond" size="5"><h2>Please wait....</h2></font></td></tr>
<tr>
<td >
<img id="progressbar">
</td>
</tr>
</table>
</div>

</div>
</div>
surya naidu
Ranch Hand

Joined: Jul 26, 2010
Posts: 32
The way you have coded...You have both the items on the same page

I mean the image to show that your data is loading and the activity which happens before the image is shown

But the requirement which i have is in such a way that.....There are two individual pages....

Once a button is pressed on a JSP (1st page) a new window opens up......which shows the result((Second page)Image has to be shown on this page)
seshu Palamanti
Ranch Hand

Joined: Jul 03, 2004
Posts: 59
you would have to use a java script that opens a window which contains your loading image and in the page add another function that closes window when it refreshes with the result. You would have to set a flag in the response when you finish rendering your page and use to toggle the loading window.
[code=java][/code]



function openWinLoader()
{
if(win_name == null)
win_name=window.open('jsp/LoadPage.jsp','Loading' ,'status=no,scrollbars=no, resizable=no,menubar=no,top=300,left=300,height=200,width=400');
else
{
//if(!win_name.open)
win_name=window.open('jsp/LoadPage.html','Loading' ,'status=no,scrollbars=no, resizable=no,menubar=no,top=300,left=300,height=200,width=400');
}
}
openWinLoader();
function closeWindow()
{
if(win_name.closed)
{
return ;
}
win_name.close();
}




window.onLoad="setDefault()"
function setDefault()
{
var sFlag = "<%=sFlag%>";
if(sFlag == 1)
{
closeWindow()
return
}


}

function submitForm(theForm)
{

openWinLoader();
}
surya naidu
Ranch Hand

Joined: Jul 26, 2010
Posts: 32
Hey i have tried what you have suggested...But i think am missing something here

I have a JSP(which i am on right now...I open a new window from here,this window shows the result data...which takes time to load)

I call function openWinLoader() from the JSP which i am on right now
but inside the function you have win_name you are doing a null check on
initially there is no window....???

According to your code do you open the window with a image first and then close it when you get data on the other one???
OR
both the windows one with the image and the other with the result open initially and then the one with image closes later on??


Can you just elaborate on which piece of code to put on which page(Sorry am still new to JavaScript so had to dig through it...)

Thank you for the suggestion

seshu Palamanti
Ranch Hand

Joined: Jul 03, 2004
Posts: 59
The initial page loads and there are no windows the user submits the page then you call openwindow which opens the loading image, your backend process goes on and takes some time and finally when the page returns (results page) the results page contains the code to close the window. You also use a mechanism to close the window only by the results page and hence the toggle logic. The code i put it there is just give you an idea please dont take the code literally. It all depends on how how your page flow works. Hope this helps.
surya naidu
Ranch Hand

Joined: Jul 26, 2010
Posts: 32
seshu Palamanti wrote:The initial page loads and there are no windows the user submits the page then you call openwindow which opens the loading image, your backend process goes on and takes some time and finally when the page returns (results page) the results page contains the code to close the window. You also use a mechanism to close the window only by the results page and hence the toggle logic. The code i put it there is just give you an idea please dont take the code literally. It all depends on how how your page flow works. Hope this helps.



But when i open the image page and the request goes to action class to process the results......How do i set the mapping.findforward???
seshu Palamanti
Ranch Hand

Joined: Jul 03, 2004
Posts: 59
The popup window for loading image has no forward you will forward after processing your results to your result page, that page will have logic to close the window
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image while loading a page