0

I want a wait box to be displayed on the page till the Java code in the JSP finishes its execution. Is it possible, if you look at the code below, is it possible to have the waitBox displayed on the page until the "UA.activateUser(UUID);" finishes its execution.

JSP Code:

<html>
    <head>
        <title>Sorry</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width">
         <script type="text/javascript" src="ext-all.js"></script>
        <link rel="stylesheet" type="text/css" href="ext-all.css" />
        <script type="text/javascript">
                    Ext.onReady(function(){
               Ext.MessageBox.show({
                   msg:'Activating your account, please wait....',
                   progressText:'Authenticating E-Mail address',
                   width:300,
                   wait:true,
                   waitConfig:{interval:200}                   
               });
               setTimeout(function(){
                   Ext.MessageBox.hide();
                   Ext.example.msg('Welcome','Your account has been activated, You can now login');
               },8000);
           });
        </script>
    </head>
    <body>

    </body>
</html>
<%
  String UUID=request.getParameter("uuid");
  userOperation UA=new userOperation();
  UA.activateUser(UUID);

%>

1 Answer 1

2

Yes, this is possible: Just output a script element after the JSP code that hides the message box. The browser renders the page as it is received, and executes script elements as it receives them. This means, though, that you can't use Ext's onReady, because that will wait for the page load to finish.

Something along these lines:

<html>
    <head>
        <title>Sorry</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width">
         <script type="text/javascript" src="ext-all.js"></script>
        <link rel="stylesheet" type="text/css" href="ext-all.css" />
    </head>
    <body>
        <script>
        // This is executed as soon as the closing tag is received
        Ext.MessageBox.show({
            msg:'Activating your account, please wait....',
            progressText:'Authenticating E-Mail address',
            width:300,
            wait:true,
            waitConfig:{interval:200}                   
        });
        </script>
<%
  // Flush to make sure the browser is sent the above
  out.flush();
  String UUID=request.getParameter("uuid");
  userOperation UA=new userOperation();
  UA.activateUser(UUID);

  // Now that's done, output the follow-up script
%>
        <script>
        // This isn't sent until the above is complete
        Ext.MessageBox.hide();
        Ext.example.msg('Welcome','Your account has been activated, You can now login');
        </script>
    </body>
</html>

Note I've used JspWriter#flush to ensure the partial output has been sent to the browser before we activate the user.

Sign up to request clarification or add additional context in comments.

5 Comments

Genius, thank you. :-) I will mark it an answer when I am allowed after 5 mins.
Writing the code to hide the box after your Java code or using AJAX, whichever suits you better. ;)
@CharlieAffumigato: I really should have flagged up ajax as an option. It's a good alternative to the above.
@T.J.Crowder Hey When I removed the Ext.onReady(function(){}) as you did in the answer, the Wait box is not getting rendered at all.
@kapilchhattani: It may be that Ext refuses to show the box if its "ready" event hasn't occurred yet, I don't know Ext. The DOM can be manipulated then, and you can show a pop-up style message. I just don't know if you can with Ext.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.