Jump to content

Auto refresh (Confirmed on version 4.7 Community)


mrmangosir
Go to solution Solved by lucianomarqueto,

Recommended Posts

 Hi,

Thought I'd share how to create an auto share on Jasper CE 4.7. This may work on lower version, if they have the "refresh" functionality. One word of warning, this does not solve allowing only certain reports to refresh and not others, but its not too difficult.

So go to <jasperInstall>/webapps/jasperserver/web-inf/jsp/modules/viewreport/viewport.jsp.

Open the file and go to around line 80/81 and after <div id="viewerToolbar" class="toolbar"> add the below attached code. So your next task will be to have it adjustable. That is up to you how you want to be able to change that value.

Be warned that once that JSP has been saved and Tomcat restarted, *all* reports will not autorefresh.

Have fun.

Code:
<script type="text/javascript">    setInterval(function(){ document.getElementById('dataRefreshButton').click(); }, 10000); // every 5 seconds</script>
Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

  • 9 months later...
  • Solution
Hello,
I used your idea and added the option to turn on and off, so you can turn the auto refresh only the reports you want.
 
This example was done on version 5.1.
 
To add the button auto refresh change the following files:
 
in file jasperserverscriptsreport.view.runtime.js change the line 41 of
$(Report.DATA_REFRESH_BUTTON).observe( 'mouseup', function() {
 
to
 
$(Report.DATA_REFRESH_BUTTON).observe( 'click', function() {
 
in file jasperserverWEB-INFjspmodulesviewReportViewReport.jsp
on line 63 after the imports scripts add the following script
 
<script >
                       var auto
                       function iniciar()
                       {
                            auto = self.setInterval( function(){clicar()}, 300000);//5 minutos
                            document.getElementById( 'iniciar').style.display = "none";
                            document.getElementById( 'parar').style.display = "";
                       }
                       function parar()
                       {
                          auto = window.clearInterval(auto);
                          document.getElementById( 'iniciar').style.display = "" ;
                            document.getElementById( 'parar').style.display = "none";
                       }
                       
                       function clicar()
                       {
                         document.getElementById( 'dataRefreshButton').click();
                       }
                      
                     
  </script>
 
And in line 158 (before pasting the script) change the code
 
<c:if test= "${param.decorate != "no"}">
    <ul class="list buttonSet">
        <li class= "leaf"><button id="back" class= "button capsule text up" ><span class="wrap" ><spring:message code= "button.back"/><span class="icon" ></span></ span></button ></li>
    </ul >
</c:if>
 
To (just added the two buttons)
 
<c:if test= "${param.decorate != "no"}">
    <ul class="list buttonSet">
        <li class= "leaf"><button id="back" class= "button capsule text up" ><span class="wrap" ><spring:message code= "button.back"/><span class="icon" ></span></ span></button ></li>
        <li class= "leaf"><button id="iniciar" class= "button capsule text up" onclick="iniciar();" title ="Iniciar a atualização automatica a cada 5 min"/><span class="wrap" >Auto </span></ button></li >
               <li class= "leaf"><button id="parar" class= "button capsule text up" style="display :none" onclick="parar();" title= "Parar atualização automatica"/>< span class ="wrap"> Stop</ span></button ></li>
    </ul >
</c:if>
 
Be happy :D

 

Link to comment
Share on other sites

  • 9 months later...
  • 3 months later...
  • 10 months later...
In new versions edit the file ~/jasperserver/optimized-scripts/report.viewer.page.js instead of JasperServer file jasperserverscriptsreport.view.runtime.js For this look inside the file by Report.DATA_REFRESH_BUTTON to locate what should be changed as mentioned in answer (mouseup -> click)
Link to comment
Share on other sites

  • 2 years later...
  • 4 weeks later...

the problem is that that the code is using 'mouseup' event and not 'click'.

instead of the above code, you  can use:

<script>    function triggerEvent(el, type){     if ('createEvent' in document) {        // modern browsers, IE9+        var e = document.createEvent('HTMLEvents');        e.initEvent(type, false, true);        el.dispatchEvent(e);     } else {        // IE 8        var e = document.createEventObject();        e.eventType = type;        el.fireEvent('on'+e.eventType, e);     }    }     self.setInterval(function(){     var el = document.getElementById("dataRefreshButton");     triggerEvent(el,'mouseup');    },10000);    </script>[/code]

 

Link to comment
Share on other sites

  • 2 months later...
  • 3 weeks later...
  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...