Thursday, July 29, 2010

Javascript: How to Find the enclosing/parent FORM Element

I was working on a project and came across a situation where we have more than one forms being generated dynamically in one page. And each form contains lots of input fields. To identify the enclosing/parent form element on some action of input tags, I used the following code:

Put these two javascript functions in script tag under head section of your page:


function findParentForm(elem){
var parent = elem.parentNode;
if(parent && parent.tagName != 'FORM'){
parent = findParentForm(parent);
}
return parent;
}

function getParentForm( elem )
{
var parentForm = findParentForm(elem);
if(parentForm){
alert("Form found: ID = " + parentForm.id + " & Name = " +parentForm.name);
}else{
alert("unable to locate parent Form");
}

}




Here is the example to call this code:


<body>
<h3> Form 1 </h3>
<form name ="formName1" id ="formId1">
<span>
<div>
<input type ="button" name ="button1" value="button1" onclick="javascript:getParentForm(this);"/> <br/>
</div>
</span>

</form>
<hr/>
<h3> Form 2 </h3>
<form name ="FormName2" id ="formId2">
<span>
<div id ="asda" name ="divName">
<input type ="button" name ="button1" value="button2" onclick="javascript:getParentForm(this);"/> <br/>
</div>
</span>
</form>
</body>


Friday, July 23, 2010

Oracle: Generate SQL script to drop all tables of any database

In oracle there is no option to drop all the user tables, but you can achieve this by generating a scrip and run that script.
To generate a script for dropping all the user tables, simply run this query and then run the result/output of this query.


SELECT 'DROP TABLE '||table_name|| ' CASCADE CONSTRAINTS;'
FROM user_tables;

Wednesday, July 21, 2010

Eclipse getting Out of Memory

I installed latest version of JDK 1.6.21 and latest eclipse Halilos version to Windows 7 (32bit). Eclipse started crashing again and again after few minutes, giving me the out of Memory issue in logs.




Here is the exception log:


!ENTRY org.eclipse.ui 4 0 2010-07-21 09:08:30.662
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:165)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:554)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:524)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:455)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(ClasspathManager.java:443)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:423)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:193)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findLocalClass(BundleLoader.java:370)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:446)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:399)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:387)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.eclipse.wst.sse.ui.StructuredTextEditor.createActions(StructuredTextEditor.java:1277)
at org.eclipse.ui.texteditor.AbstractTextEditor.createPartControl(AbstractTextEditor.java:3362)
at org.eclipse.ui.texteditor.StatusTextEditor.createPartControl(StatusTextEditor.java:53)
at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.createPartControl(AbstractDecoratedTextEditor.java:394)
at org.eclipse.wst.sse.ui.StructuredTextEditor.createPartControl(StructuredTextEditor.java:1362)
at org.eclipse.ui.part.MultiPageEditorPart.addPage(MultiPageEditorPart.java:217)
at org.eclipse.ui.part.MultiPageEditorPart.addPage(MultiPageEditorPart.java:187)
at org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart.addSourcePage(XMLMultiPageEditorPart.java:435)
at org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart.createPages(XMLMultiPageEditorPart.java:605)
at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:310)
at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:661)
at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:428)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:594)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:306)
at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)

Solution:

After struggling with this, I found this issue is due to the latest JDK v1.6.21. Best is to use the stable version of JDK that is: JDK v 1.6.20 and configure it accordingly.
Hopefully it will resolve the issue, if still getting the issue add following line after "-vmargs" to your eclipse.ini file:
-XX:MaxPermSize=256m
The eclipse.ini file can be found under eclipse directory. It will be someting like this:

eclipse.ini
---------------
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
512M

-framework

plugins\org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar

-vm

C:\Program Files\Java\jdk1.5.0_22\bin

-vmargs

-XX:MaxPermSize=512m

-Dosgi.requiredJavaVersion=1.5

-Xms128m

-Xmx1024m

---------------