0 Replies Latest reply on Jul 21, 2012 6:55 PM by sivaji.balla

    I'm having trouble running the example of remoting (sayHello), usually works in IE but in FireFox is showing a popup with error.  when we perform operations using <a4j:commandButton> ,<a4j:commandLink>,<h:comm

    sivaji.balla Newbie


      my script file is:
      <script> 
          function closeIt() { 
              return "Any string value here forces a dialog box to \n" + 
               "appear before closing the window. Do what you have to do in this method."; 
          } 
          window.onbeforeunload = closeIt; 
      </script>
      <s:remote include="browserclass"/>
      <script type="text/javascript">
      window.onbeforeunload = function sayHello() {     
      var wtname=Seam.Component.getInstance("browserclass").browser_close_method();    
      }
      </script>

      ---------------------------------------
      And my java file is:
      package org.domain.ezXXX.session;

      import java.math.BigDecimal;
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.PreparedStatement;
      import java.text.SimpleDateFormat;
      import java.util.Date;

      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.remoting.WebRemote;

      @Name("browserclass")
      @Scope(ScopeType.SESSION)
      public class BroserClass  {

      @In(required=false)
      AuthenticatorIF authenticator;
      @WebRemote
      public void browser_close_method(){
      java.sql.Timestamp browserclosesqlDate = new java.sql.Timestamp(new java.util.Date().getTime());
      System.out.println("---------------------this is getting login userid123---------------"+authenticator.getLoginuser_id());
      System.out.println("----------------------this browser closing time-----------------------------"+browserclosesqlDate);
      System.out.println("----------------------ok this is getting-----------------------"+authenticator.getPersist_login_history_id());
      Connection connection = null;              
      try {                   
      java.sql.Timestamp browserclosetime = new java.sql.Timestamp(new java.util.Date().getTime());                        
      // Load the JDBC driver         
      String driverName = "oracle.jdbc.driver.OracleDriver";
      Class.forName(driverName);        
      // Create a connection to the database
      String serverName = "localhost";
      String portNumber = "1521";
      String sid = "xxxxxx";
      String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
      String username = "xxxxxx";
      String password = "xxxxx";
      connection = DriverManager.getConnection(url, username, password);
      System.out.println("-----------------------this is connection established-------------"+connection);           
      String updateendtime="UPDATE LOGIN_HISTORY SET END_TIME = ? where LOGIN_ID="+authenticator.getPersist_login_history_id();        
      System.out.println("--------------this is query----------------"+updateendtime);
      PreparedStatement prest = connection.prepareStatement(updateendtime);            
      prest.setTimestamp(1, browserclosetime);       
      prest.executeUpdate();
      SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");                    
      String time1 = format1.format(authenticator.getTimestamp());              
      String time2 = format1.format(browserclosetime);              
      Date date1 = format1.parse(time1);
      Date date2 = format1.parse(time2);
      long difference = date2.getTime() - date1.getTime();
      long diffMinutes2 = difference / (60 * 1000);
      BigDecimal duration = BigDecimal.valueOf(diffMinutes2);
      System.out.println("------------------this is the duration time----------"+duration);         
      String updatespenttimerecord1="UPDATE LOGIN_HISTORY SET TIME_SPENT = ? where LOGIN_ID="+authenticator.getPersist_login_history_id();
      System.out.println("--------------this is query1------"+updatespenttimerecord1);
      prest = connection.prepareStatement(updatespenttimerecord1);         
      prest.setBigDecimal(1, duration);
      prest.executeUpdate();
      prest.close();                                
      } catch (Exception e) {
      // Could not connect to the database
      }finally{
      try{              
      connection.close();
      }catch (Exception e) {
      e.printStackTrace();
      }
      }

      }

      }


       

      could please help me  on above issue.