Posts

Fixing my HTC Desire's wifi

I recently did an Over The Air (OTA) update of my new HTC Desire from 2.09 to 2.10. The update all seemed to run correctly. However I soon noticed that the wifi wasn't working. Looking in settings, it showed wifi was disabled and when you try and enable it, you just get "error". Seems like other people have been getting this as well. I tried following their advice, reset the factory defaults but that didn't work. I couldn't get the recovery mode to load (in order to wipe the caches) - after some brief searching it appeared that this was due to root access so I gave up on that. NOTE: it turns out I was doing it wrong. After selecting the recovery option a red triangle with an exclamation point is show. At which point you need to press volume+ and power to show the next menu. Next I tried using latest RUU (2.10) but got Error 170 Usb Connection Error . One post mentions under 'update': HTC has released a new Froyo OTA update. You can install this dire...

Escaping a regex expression

I was working on a project where I needed to dynamically generate a regular expression based on some user input but the string to search for needed to be escaped. Below is the quick and dirty way to do it: /** * Utility function to replace regular expressions. * * @param input * @return */ private static String escapeRegex(String input) { String special[] = { "\\", "[", "]", "^", "$", ".", "|", "?", "*", "+", "(", ")" }; String val = input; for (String replace : special) { val = val.replace(replace, "\\" + replace); } return val; }

Tomcat DBCP: Data source is closed

After updating to the latest version of Tomcat I started getting the following error when redeploying a webapp from inside eclipse: java.sql.SQLException: Data source is closed     at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1362)     at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) It seemed to be related to an updated version of DBCP that is used inside tomcat (I get Tomcat to manage my datasource). After tracing the code a bit I discovered it was because I called this, in my Filter.destroy() to do clean up: ((BasicDataSource) dataSource).close(); Older versions of Tomcat (6.0.26 and below), didn't care if you called it. When the webapp was reloaded, the datasource still worked. But as of 6.0.28, the newer version of DBCP seems to cause problems. So if you want to clean up after the webapp, use the removeAbandoned attribute in the Tomcat Configuration on the datasource...

Portable java environments on windows

I always seem to be copying my development environment between PCs and latops which end up being time consuming. Its not the size of the data, its the number of small files (mainly javadoc & java source) that slow the whole process down. I already store the source code and workspace for my clients in a TrueCrypt Volume , to prevent my code being stolen if someone were to get hold of my laptop. All the other necessary files I need for development; such as libraries, jdk, tomcat/jboss, elcipse etc; are stored on my hard drive. In some cases on different drive letters on different computers. So to simplify this I wanted to store them in a similar way to a TrueCrypt volume but without the overhead of encryption and the hassle of mounting it. After some poking around I remember that Windows 7 came with built-in support for creating and mounting Virtual Hard Disk (VHD) straight from the Storage Manager. The VHD are used by Virtual PC. For those running Vista, Virtual PC 2007 should s...

EL Coerces empty/null to ZERO

I recently came across a problem where I was expecting a null value to be populated into one of my JSF managed beans on submit. After digging through the entire stack, I found out this was deliberate. This bug was introduced into Tomcat 6.0.16, as a consequence of implementing the EL spec to the letter. The option to disable this change at command line was added in 6.0.17: -Dorg.apache.el.parser.COERCE_TO_ZERO=false A patch in Tomcat 6.0.24  was added to allow you to change it at run time: System.getProperties().put("org.apache.el.parser.COERCE_TO_ZERO", "false"); This problem also directly occurs in JSF, as it uses an EL engine as well. There's a  patch for 1.2_08-b01  but it is happening in 2.0.2. But the above fix seems to work. Request to change the JSP Spec As per chapter 1.18.2 and 1.18.3 of EL spec, EL coerces null values to non-null values such as empty String or (Long) 0 or (Boolean) false. This behaviour is in almost all cases unwanted when t...

A simple way to Inject Guice into JSF (Mojarra)

Previously I have been using GuiceSF to inject the JSF managed beans which extends the Mojarra's implementation of ELResolver ( ManagedBeanELResolver ). This was bit of a hack but it was relatively simple to implement. In upgrading to newer version of JSF, I had to manually tweak it to keep it in line with the new features in the spec which took a fair amount of debug stepping. So when JSF 2 came out I looked around for a way to do it which still used the implementation's bean creation and handling but also injected it with Guice. After digging around in the injection code in Mojarra, I saw how simple it would be to extend the provided Tomcat injection (which injects stuff for the @Resource and @EJB etc annotations). This solution first requires the injection provider be specified in web.xml: <context-param> <description>JSF Injection provider</description> <param-name>com.sun.faces.injectionProvider</param-name> <param-value...

Converting custom JSF 1 components to JSF 2

These are just some observations/tips I made when converting my JSF 1 components to JSF 2. Simpler .taglib.xml The taglib definition changes from mycomponent.tld to mycomponent.taglib.xml . The xml inside the new file is similar but with some changes (i.e. <name> becomes <tag-name>). The major simplification is that attributes no longer need to be defined. Just the tag-name and component-type. <tag> <name>menuItem</name> <tag-class>net.devgrok.component.MenuItemTag</tag-class> <body-content>JSP</body-content> <attribute> <name>value</name> <required>false</required> <deferred-value> <type>java.lang.String</type> </deferred-value> </attribute> </tag> Becomes: <tag> <tag-name>menuItem</tag-name> <component> <component-type>net.devgrok.MenuItem</component-type> </component> </tag> And the newly...