Sunday, 5 September 2010

Debugging JavaScript in Internet Explorer (IE)

Recently, I was required to debug JavaScript in Internet Explorer (IE). JavaScript debugging is disabled by default. Most of companies disable editing advanced options of IE. So one need to edit registry settings in order to enable JavaScript debugging. Remember, you need permission to modify registry settings. If you are not sure of changes, it is a good idea to take back up of registry by using File -> Export option from Registry Editor.

The steps to enable JavaScript debugging in IE, follow the steps as mentioned below:
  1. Close all Internet Explorer windows.
  2. Open Registry Editor (Start -> Run -> regedit)
  3. Search for Disable Script Debugger key (Ctrl + F)
  4. The key will be present under [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main] 
  5. Edit key "Disable Script Debugger"
  6. Set value to "no"
  7. Start Internet Explorer
And you are all set to debug JavaScript in IE. You may find Microsoft Script Editor as good option to debug JavaScript, if you do not have Visual Studio installed. Generally, path of Microsoft Script Editor on Windows is "C:\Program Files\Microsoft Office\Office10\MSE7.EXE"

Tuesday, 25 August 2009

java.sql.SQLException: Access denied for user 'root'@'localhost'

I'd spend good amount of time getting my head around starting with MySQL database on my laptop.

Apart from other problems I faced, the following was a tricky exception:

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:917)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3974)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1282)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2142)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:773)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:46)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Native Method)


I got this resolved on my laptop. I made 2 changes before the issue was fixed. The two steps which I performed were:

  1. GRANT ALL PRIVILEGES to root user
  2. DELETE root user using SQL


The most obvious step which should have fixed the issue is granting privileges to root user. And details of step I performed are as below:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'admin' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

However, as you notice the rows affected were 0. And my feeling is this is not what had made the difference.

I will warn you before you do the next step which was deleting root user using SQL. When I looked at user table in MySQL I noticed that I had two root users. The one was with host as localhost and other was with host as 127.0.0.1. The later did not have password. I've compared every field and both root records in User had identical values for all fields except host and password.

So I decided to delete the root user entry from User table, which did not have password and had value of host set to 127.0.0.1. The query tried was as below:

mysql> delete from user where user ='root' and host='127.0.0.1';
Query OK, 1 row affected (0.02 sec)

MySQL - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

While connecting to My SQL database, I got following error message:


com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


I had personal firewall software running, which was blocking default TCP port which MY SQL clients used to connect to the database server. When I opened TCP port 3606, I managed to resolve the Communications link failure problem.

Monday, 24 August 2009

Grails - Error generating scaffolded view

While running Grails application with dynamic scaffolding, I got following error:


Error generating scaffolded view [/product/index]: C:\grails\grails-1.1.1\src\grails\templates\scaffolding\index.gsp (Th
e system cannot find the file specified)
java.io.FileNotFoundException: C:\grails\grails-1.1.1\src\grails\templates\scaffolding\index.gsp (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:106)


The problem was caused because I had index defined in my auto generated Controller class.

For Example:
class BookController {
def scaffold = Book

def index = { }
}
In above case, removing index resolved my problem.

Grails - java.lang.SecurityException: Prohibited package name: java.lang

I installed grails on my laptop today and was curious to try out my grails application. But I was presented with long scary error stack trace.


java.lang.SecurityException: Prohibited package name: java.lang
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:479)
at java.lang.ClassLoader.defineClass(ClassLoader.java:614)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at org.codehaus.groovy.tools.RootLoader.oldFindClass(RootLoader.java:152)
at org.codehaus.groovy.tools.RootLoader.loadClass(RootLoader.java:124)
at org.codehaus.groovy.grails.cli.support.GrailsRootLoader.loadClass(GrailsRootLoader.java:43)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at org.codehaus.groovy.tools.RootLoader.oldFindClass(RootLoader.java:152)
at org.codehaus.groovy.tools.RootLoader.loadClass(RootLoader.java:124)
at org.codehaus.groovy.grails.cli.support.GrailsRootLoader.loadClass(GrailsRootLoader.java:43)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.codehaus.groovy.grails.cli.support.GrailsStarter.rootLoader(GrailsStarter.java:177)
at org.codehaus.groovy.grails.cli.support.GrailsStarter.main(GrailsStarter.java:212)


I inspected classpath on my laptop and found that I'd %JAVA_HOME%\jre\lib\rt.jar in my classpath. When I removed rt.jar from classpath, grails was working fine.

Wednesday, 19 August 2009

Supporting maxlength for textarea using jQuery


/*
* Plugin for jQuery JavaScript Library
* http://dev-lessons-learned.blogspot.com/
*
* Copyright (c) 2009 Sandesh Tathare
* Licensed for free use.
*
* Date: 2009-08-20 10:15
* Revision: 001
*/
$(document).ready(function (){
maxlength();
});

function maxlength(){
$("textarea[maxlength]").each(function(){
var maxlength = ($(this).attr("maxlength"));
$(this).keypress(function(event){
if(maxlength < ($(this).val().length + 1)){
event.preventDefault();
}
});

$(this).keyup(function(event){
if(maxlength < ($(this).val().length)){
$(this).val($(this).val().substring(0,maxlength));
}
});
});
}