Getting JavaScript CSS Dropdown Menu to Render Over a Flash Component

If you are having trouble getting a DHTML drop-down menu to display on top of a Flash movie try adding the following to the <object> tag that embeds the .swf file in your .html.

Add the following as a child to the <object> tag:

<param name=”wmode” value=”transparent” />

Add the following as an attribute to the <object> tag:

wmode=”transparent”

I was having trouble getting a JavaScript dropdown to render over a Flash movie under IE and after adding the aforementioned tags it works just fine.

Compiling .jsp Fragments in Eclipse

The ability to generate HTML or .JSP fragments that you can include on multiple pages of your site enables you to re-use code and increase maintainability.

However, if you need to include functions (or methods) and fields (or variables) in one fragment that is included on a page and then utilize them in another fragment included in the same page Eclipse will give you compile errors because it concludes that your references are out of scope.

The solution is quite simple:? Instead of naming the fragments .jsp, use some other extension (.jnc, .jinc, etc) for the fragements that contain references to variables or functions that are included on the parent page and use the <%@ include %> directive as this includes the content of the fragment at compile time.

Accessing JSON Data Under IE7

Given the following JSON object:

var var_affectedAreas = {
? ? ‘areaCount’ : 6,
? ? ‘areasList’: [
? ? ? {‘enum’: ‘FILE’, ‘val’: ‘F’},
? ? ? {‘enum’: ‘REGISTRY’, ‘val’: ‘R’},
? ? ? {‘enum’: ‘PROCESS’, ‘val’: ‘P’},
? ? ? {‘enum’: ‘MEMORY’, ‘val’: ‘M’},
? ? ? {‘enum’: ‘NETWORK’, ‘val’: ‘N’},
? ? ? {‘enum’: ‘OTHER’, ‘val’: ‘O’}
? ? ]
};

You would think (and rightly so, at least under Firefox) that you would be able to access data in this object via the following:

areaCell = var_affectedAreas.areasList[var_areasCount].enum;
areaCell = eval(“var_affectedAreas.areasList[” + var_areasCount + “].enum”);
areaCell = eval(“var_affectedAreas.areasList[‘” + var_areasCount + “‘].enum”);

However, IE7 does not like that syntax and throws syntax errors.

The following syntax works under both IE7 and Firefox.

areaCell = var_affectedAreas[“areasList”][var_areasCount][“enum”];

Setting up Cygwin, Linux Command Line, on a Windows Box

For all of you Linux (and Unix) users who are used to the Linux command line there is an application called Cygwin. Not only does it allow you to use the familiar command line commands but it also includes the ability to execute bash and csh shell scripts on a Windows machine.

When installing it, here are a few additional packages you’ll probably want to include:

vim, ncurses, tcsh

Simply type them into the search field and then check off those packages.

Applying Order to JSON Data When Rendering to a Page

It is very convenient to pass JSON data from client to server and between different server-side components. However, JSON data is an inherently unordered data structure and in many cases a developer will want to render a list of items in some specified order.

One way that I found to do so is to append an integer to the keys in your data when generating the JSON data. For example, you might be iterating through a database result set and want to maintain the order in which the result was returned. When adding your keys append ‘_n’ to the string.

Then, when you access the JSON data (with JavaScript, and jquery, and assuming a reference to your JSON data is ‘data’) first get a count of the number of objects in your JSON container:

$counter = 0;

$.each(data, function(key, value) {

? $counter++;

alert(key + ‘: ‘ + eval(value.id));

});

Now we have a count of the number of items in the object and run a for loop using the $counter variable.

for(var $rowCounter = 0; $rowCounter < $counter; rowCounter++) {

? // Access your data using the $rowCounter value

? alert(“row ” + $rowCounter + ” = ” + eval(“data.row_” + $rowCounter));

}

Opening a New Window From a Web Page with Javascript that is SEO Friendly

The days of <a href=”#” target=”_blank”></a> are long gone. The way to open a new window with a link is to do it using the javascript window.open() method via an onclick callback.

However, you still want to make your pages SEO friendly, so you don’t want to go about generating links with href=”#”. The way to do it is as follows:

Javascript:

<script>

function openNewWindow(url) {

   window.open(url);

}

</script>

HTML:

<a href=”someURL.html” onclick=”openNewWindow(‘someUrl.html’);return false;”>Link</a>

When implementing links this way, you still include the url in the href attribute making the page SEO friendly and implement the new window functionality via your javascript function. You must make sure to include return false; in your onclick attribute so that the link doesn’t load in the window from which the original click was issued.

Using bash Shell to Rename Files With Spaces

The following is a shell command that you can use to rename any file that contains spaces. Without the quotes surrounding the $file reference and the echo command it will fail.

In this example, we rename anything that is .htm to .html

for file in *.htm ; do mv “$file” “`echo “$file” | sed ‘s/\(.*\.\)htm/\1html/’`” ; done

java.lang.reflect.UndeclaredThrowableException When Attempting to Invoke a Remote Method on an EJB Singleton Instance

I am building an EJB Singleton that generates and maintains data that I want accessible to multple clients. Since the data is not based on any client interaction but based on the status of a single server-side application I went with an EJB Singleton.

When attempting to invoke a method via the Remote interface on the bean instance from a servlet in a separate .war which was returning a LinkedList of a custom Object that I wrote, I was getting the following error:

2011-03-15 13:17:59,232 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/DocumentRoot].[ServletClass]] (http-localhost%2F127.0.0.1-8080-3) Servlet.service() for servlet ServletClass threw exception: java.lang.reflect.UndeclaredThrowableException
       at $Proxy236.ejbRemoteMethod(Unknown Source)    at ServletClass.doGet(ServletClass.java:52) [:]
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [:1.0.0.Final]
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.Final]
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final]
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.Final]
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final]
       at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
       at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]
       at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]
       at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final]
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final]
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]
       at java.lang.Thread.run(Thread.java:636) [:1.6.0_17]
Caused by: java.io.IOException
       at org.jboss.serial.persister.RegularObjectPersister.readSlotWithMethod(RegularObjectPersister.java:107) [:6.0.0.Final]
       at org.jboss.serial.persister.RegularObjectPersister.defaultRead(RegularObjectPersister.java:269) [:6.0.0.Final]
       at org.jboss.serial.persister.RegularObjectPersister.readData(RegularObjectPersister.java:241) [:6.0.0.Final]
       at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.readObjectDescriptionFromStreaming(ObjectDescriptorFactory.java:412) [:6.0.0.Final]
       at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.objectFromDescription(ObjectDescriptorFactory.java:82) [:6.0.0.Final]
       at org.jboss.serial.objectmetamodel.DataContainer$DataContainerInput.readObject(DataContainer.java:845) [:6.0.0.Final]
       at org.jboss.serial.io.MarshalledObjectForLocalCalls.get(MarshalledObjectForLocalCalls.java:60) [:6.0.0.Final]
       at org.jboss.ejb3.remoting.IsLocalInterceptor.marshallOrPass(IsLocalInterceptor.java:117) [:1.7.17]
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:91) [:1.7.17]
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:75) [:1.7.17]
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
       at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62) [:1.0.1.GA]
       at $Proxy181.invoke(Unknown Source)    at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:185) [:1.0.11]
       … 23 more
Caused by: java.lang.reflect.InvocationTargetException
       at sun.reflect.GeneratedMethodAccessor409.invoke(Unknown Source) [:1.6.0_17]
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [:1.6.0_17]
       at java.lang.reflect.Method.invoke(Method.java:616) [:1.6.0_17]
       at org.jboss.serial.persister.RegularObjectPersister.readSlotWithMethod(RegularObjectPersister.java:103) [:6.0.0.Final]
       … 36 more
Caused by: java.io.IOException
       at org.jboss.serial.persister.RegularObjectPersister.readSlotWithMethod(RegularObjectPersister.java:107) [:6.0.0.Final]
       at org.jboss.serial.persister.RegularObjectPersister.defaultRead(RegularObjectPersister.java:269) [:6.0.0.Final]
       at org.jboss.serial.persister.RegularObjectPersister.readData(RegularObjectPersister.java:241) [:6.0.0.Final]
       at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.readObjectDescriptionFromStreaming(ObjectDescriptorFactory.java:412) [:6.0.0.Final]
       at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.objectFromDescription(ObjectDescriptorFactory.java:82) [:6.0.0.Final]
       at org.jboss.serial.objectmetamodel.DataContainer$DataContainerInput.readObject(DataContainer.java:845) [:6.0.0.Final]
       at org.jboss.serial.persister.ObjectInputStreamProxy.readObjectOverride(ObjectInputStreamProxy.java:68) [:6.0.0.Final]
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:362) [:1.6.0_17]
       at java.util.HashMap.readObject(HashMap.java:1047) [:1.6.0_17]
       … 40 more
Caused by: java.lang.reflect.InvocationTargetException
       at sun.reflect.GeneratedMethodAccessor408.invoke(Unknown Source) [:1.6.0_17]
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [:1.6.0_17]
       at java.lang.reflect.Method.invoke(Method.java:616) [:1.6.0_17]
       at org.jboss.serial.persister.RegularObjectPersister.readSlotWithMethod(RegularObjectPersister.java:103) [:6.0.0.Final]
       … 48 more
Caused by: org.jboss.serial.exception.SerializationException: Could not create instance of org.jboss.logmanager.log4j.BridgeLogger – org.jboss.logmanager.log4j.BridgeLogger
       at org.jboss.serial.classmetamodel.ClassMetaData.newInstance(ClassMetaData.java:342) [:6.0.0.Final]
       at org.jboss.serial.persister.RegularObjectPersister.readData(RegularObjectPersister.java:239) [:6.0.0.Final]
       at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.readObjectDescriptionFromStreaming(ObjectDescriptorFactory.java:412) [:6.0.0.Final]
       at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.objectFromDescription(ObjectDescriptorFactory.java:82) [:6.0.0.Final]
       at org.jboss.serial.objectmetamodel.DataContainer$DataContainerInput.readObject(DataContainer.java:845) [:6.0.0.Final]
       at org.jboss.serial.persister.RegularObjectPersister.readSlotWithFields(RegularObjectPersister.java:353) [:6.0.0.Final]
       at org.jboss.serial.persister.RegularObjectPersister.defaultRead(RegularObjectPersister.java:273) [:6.0.0.Final]
       at org.jboss.serial.persister.RegularObjectPersister.readData(RegularObjectPersister.java:241) [:6.0.0.Final]
       at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.readObjectDescriptionFromStreaming(ObjectDescriptorFactory.java:412) [:6.0.0.Final]
       at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.objectFromDescription(ObjectDescriptorFactory.java:82) [:6.0.0.Final]
       at org.jboss.serial.objectmetamodel.DataContainer$DataContainerInput.readObject(DataContainer.java:845) [:6.0.0.Final]
       at org.jboss.serial.persister.ObjectInputStreamProxy.readObjectOverride(ObjectInputStreamProxy.java:68) [:6.0.0.Final]
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:362) [:1.6.0_17]
       at java.util.LinkedList.readObject(LinkedList.java:981) [:1.6.0_17]
       … 52 more
Caused by: java.lang.InstantiationException: org.jboss.logmanager.log4j.BridgeLogger
       at java.lang.Class.newInstance0(Class.java:357) [:1.6.0_17]
       at java.lang.Class.newInstance(Class.java:325) [:1.6.0_17]
       at org.jboss.serial.classmetamodel.ClassMetaData.newInstance(ClassMetaData.java:334) [:6.0.0.Final]
       … 65 more

After some fairly extensive experimentation I determined that the error was the result of a composed instance org.apache.log4j.Logger. Even though I included the same version of the log4.jar file in both the ejb.jar and the .war file it seems as though the class loader was having problems marshalling the Logger instance.

Had I the time to fully get it sorted out so that I could use the Logger instance in the custom class that I was returning I would, but alas . . . the rest of the project awaits.

Updating the URL of a Subversion Repository in a Currently Checked Out Copy of Your Repository

Let’s say you have a server who’s IP address or domain name changes on which you have a Subversion repository. Furthermore, you have checked out the copy over an ssh connection using svn+ssh.

If you have checked-out copies of your repo, and the path to the repo on the file system hasn’t changed, but only the IP or domain name has changed you need to issue the following command in the root of your checked out copy:

svn switch –relocate svn+ssh://user@old.domain/ svn+ssh://user@new.domain/

Authenticate to the new machine.

svn update

Authenticate again.

Done.