Skip to main content

Posts

Showing posts from 2011

Do 'is' boolean methods work in JSPs with JSTL?

When coding in JSTL you often want to use conditional logic (I'm thinking and the like) to be able to structure your page correctly. Auto-generated getter & setter methods will normally create isX() methods for the getters of boolean values (at least in Eclipse it does) but can you access this method directly from JSTL without writing a getX() version? Does JSTL support 'is' boolean methods though? Ask a random poll of Java we developers and you will get conflicting answers so I decided to investigate, want the short answer? YES - JSTL does support accessing isX() methods directly as if you were accessing a getX() method, but only if the return type of the isX() method is a primative boolean . If you return an object of any kind (such as Boolean isObjectBooleanTrue()) then JSTL fails to find the method and will give you a rather nasty JSP exception: javax.el. PropertyNotFoundException: The class 'com.andrewbeacock.BooleanTest' does not have the pr

How to stop Eclipse reformating your Java enumerations & comments

Eclipse is a wonderful IDE for the Java language and I’ve used it daily for at least the past 4 years but it does have some 'issues'. One is regarding it’s code formatting (or reformatting) support, normally it does a great job of putting stuff in the right place but there are occasions where it just fails to get it right. Enumerations When I write enums I like to have each item on it's own row, I find it's easier to read and amend in the future: public enum Family { MOTHER, FATHER, DAUGHTER, SON; } But Eclipse has other ideas and formats it so that it looks like this: public enum Family { MOTHER, FATHER, DAUGHTER, SON; } A way to get around this (and any other times where you have a few lines of code that you don't want collapsing into one is to add the double-slash style code comments to the end of each line: public enum Family { MOTHER, // FATHER, // DAUGHTER, // SON; } Block comments I recently wanted to have a decent

Always note DNS server settings offline

Had a strange experience this evening - complete loss of the internet. My router was suggesting that I had ASDL connectivity, and even an IP address but I wasn't able to load any websites. After a bit of debugging with the help of a remote friend I figured out that I wasn't able to connect to my OpenDNS name servers and so google.com wasn't resolving for me. I updated my router with Google's DNS settings and was back in play - just goes to show that what appears to be an ISP outage can be a case of name servers not being available at that time. Make sure you make a note of a few free DNS server details (i.e. both OpenDNS and GoogleDNS ) offline so you can try them out if you ever end up 'offline'!

Misleading wiring messages with aliased Spring DataSources

When accessing databases in Spring you commonly use a dataSource.xml file of some description to hold the XML stanzas describing the connection details to various databases or schemas. When dealing with multiple dataSource requirements you might find that more than one logical dataSource bean name actually points to the same physical connection. Rather than define multiple datasource stanzas with exactly the same details, Spring allows the use of the element to point easily to an existing bean but use a different name: <bean id="personDataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@database:port:SID" /> <property name="username" value="USER" /> <property name="password" value="PASS" />

Sound advice for a source code commit frequency

A colleague of mine commented recently in a discussion on how often one should commit their source code: commit on keyup     - always tends to keep everything as up to the minute as possible Classic! and yes it was tongue in cheek advice!

Using & comparing enumerations (enums) with JSTL

Often in your JSTL pages you will want to test a value of a particular variable before displaying something on the page. Often you are comparing against primitive types or other objects but what if you want to compare against an enumerated type ? Attempting to access the enumeration directly as Colour.BLUE doesn't work as the class/enum isn't available but what you can do it compare objects against their label or enum name. If we have a Colour enumeration: public enum Colour { RED, GREEN, BLUE } and we have a car object which has a getColour() method on it (returning the enumerated type) we can test against it in JSTL by using the specific name: <c:if test="${car.colour eq 'BLUE'}">

Keyboard shortcut for 'paste as plain text' in Pidgin

I use Pidgin at work for communicating with my remote colleagues and I regularly paste code snippets and log file output into the Pidgin window. Often the text formats completely wrong and you end up sending the recipient a page of garbage rather than the real text. Pidgin has a right-click context menu option for getting round this called 'paste as plain text' which normally does the trick but what if you normally use CTRL-V to paste your text in? After 2 seconds of experimentation today I found that CTRL-SHIFT-V is the keyboard shortcut for 'paste as plain text', I now feel complete...

Embedding a Google Docs spreadsheet in Blogger

Blogger is an excellent free blogging platform but if you want anything 'dynamic' then it starts to get in the way. One thought I've had recently was to see how I could share information captured in Google Docs Spreadsheet with Blogger. I've a few ideas which will take a few posts to explain, so let's start with the most basic - embedding a Google Spreadsheet direct into Blogger. Access the spreadsheet in Google Docs that you want to expose in Blogger, I've chosen a simple table of the most popular programming languages in 2010: Next you'll want to share this spreadsheet with the rest of the world by publishing it as a web page: Now you need to select the "HTML to embed in a page" option and copy the HTML code into the clipboard:  Open a new post in blogger and ensure that the "Edit HTML" tab is selected and paste the code in: Now publish your post and your spreadsheet will be visable in your blog post: I didn't say