Skip to main content

Posts

Showing posts with the label Web

Beware of JavaScript's parseInt function - 010 does not equal 10...

I use JavaScript & jQuery quite a bit in my day job helping to add a bit of 'shiny' to our web applications. One feature that I added recently kept a track of the percentages that you had typed in the form.  It told you at the bottom of the page how much percentage you had left - I used JavaScript's parseInt function to help me in this respect. As the application passed through system test it was found that if you typed '020' as a percentage my application said that you had 84% left to assign rather than the expected 80% - any ideas what's going on? Yes that's right - the leading zero was causing parseInt to treat the number as an octal (base 8) number and so 020 was two lots of 8 = 16. It appears that this octal recognition is being deprecated but who knows when it will actually go so for now I've had to add ", 10" (i.e. a decimal radix) to the end of all of my parseInt calls: parseInt(percentage, 10); Double check any code that you...

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...

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'!

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'}">

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...

Accessing & iterating over a Java Map in a JSP page with JSTL

When you are coding JSP pages using JSTL one thing you use a lot is the <c:foreach> tag . This tag a great for iterating over Lists or Sets but what do you do when you want to display the contents of a Map ? Firstly you need to decide how you are going to use the Map. Do you want to access a 'value' stored within the Map based on a known key or iterate over the Map displaying both key and value? Access a Map based on a 'key' This one is pretty straight forward you just need to know the JSTL syntax: ${aMapFullOfKeysAndValues[yourKnownKey]} Two key points: The key is an existing JSTL variable or a quoted string You use square brackets at the end of the Map name Iterate over a Map pulling out the 'key' & 'value' This is a little more complex, note the name of the variable that is filled on each pass through the Map ('entry'): ${entry.key} - ${entry.value} Four key points: The name of the Map is placed as the 'i...

Have more than one gmail account?

Not sure if you are aware of this but Google have added a rather funky dropdown account selector to a number of their applications, more details are here: Access two Gmail accounts at once in the same browser A damn fine invention if you ask me!

iPhone version of the excellent Password Composer

I've been using the excellent Password Composer Greasemonkey script for Firefox for over 2 years now - it's a great way to ensure that your master password isn't spread around the web yet never gets in the way of accessing a site. My collegue Andy Kayley recently pointed out that there is an iPhone version available so that you can easily access your Password Composer encrypted passwords whilst on the move!  It's written by Jon Parise and not only does he include a link to his version but also goes into excellent detail on how he developed the iPhone application! Now I just need to get myself an iPhone... ;)

googlemail is going, gmail returns (if you're in the UK)

This might be old news now but Google now have the ability to use 'gmail.com' for UK people rather than the awkward 'googlemail.com': Why did you change the name from Google Mail to Gmail? A little more than a year after Gmail first launched, Google changed the name of its webmail service in the United Kingdom to "Google Mail" due to negotiations over a trademark dispute. We have reached a settlement, so we are happily changing the name back to Gmail, and offering @gmail.com addresses to all Google Mail users in the UK. Plus, it's shorter and easier to type this way :) There's more information about it here: Google Mail is becoming Gmail in the UK Technorati Tags: Google , Gmail , Andrew Beacock

Firebug is a jQuery console test/debugging tool too!

I thought everyone knew this, but after a chat with a couple of colleagues this week it seems that most don't know that... ...if you use Firebug (in Firefox ) on a jQuery -enabled website, Firebug 's console can handle jQuery selectors and other jQuery magic . To see for yourself, make sure you have Firebug installed, then visit the jQuery home page . Ensure that the console is enabled and type the following and hit return: $('#jq-content').fadeOut() You should hopefully see most of jQuery's home page gently fade out! This feature is invaluable when investigating & debugging jQuery javascript code, make sure you install Firebug into Firefox today! Technorati Tags: jQuery , Firebug , Firefox , Andrew Beacock

jQuery tip: Selecting ids with periods in them (dots/'.')

I was messing around with jQuery today combined with a Spring form-backed bean and was finding that my jQuery was failing to work. The id of the input field bound to my Spring form was person.id . Trying to get the value entered into the input box was failing, this is what I was trying: $('#person.id').val(); The problem here is the period - '.' - jQuery see these as CSS notation and so fails to find an element with that id, what you need to do is add two backslashes ('\\') before the period to escape it, like this: $('#person\\.id').val(); See the jQuery FAQ for more details. Technorati Tags: jQuery , Spring , Andrew Beacock

Summary of March's Manchester Open Source Central User Group Meeting

I really enjoyed last night's Open Source Central user group meeting in Manchester. Both speakers were excellent and there were a lot of good ideas to take away.  Here is my summary of the evening: "Spring BlazeDS Integration" by Rick Evans He started with an overview of why build web applications with Flex & Flash : rich internet applications which look like a desktop application rather than a bunch of web pages. He then suggested that Flex & Flash applications client applications could be powered by a Spring server backend by using BlazeDS . Flex is a framework for building rich internet applications. You get the same looking application regardless of operating system or browser which can't be said for regular web-based applications. Flex applications can be deployed into the standard flash player embedded in the browser or as a desktop application via Adobe AIR.  You write Flex applications in ActionScript which is an OO language enabling a simpl...

Shorten links to be Twitter-friendly with j.mp

Any Twitter users out there will know that URLs and 140 characters don't really mix that well, especially if you actually want to talk about the link as well!  Typically you would use a URL shortening service such as the original tinyurl.com or one of the newer, shorter versions such as bit.ly . Well there is a new kid on the block who's even shorter: j.mp J.mp is another member of the bit.ly family just with two less letters, but it's going to be perfect for Twitter .  I use the bit.ly bookmarklet to generate my links but it appears that there is not a version for j.mp yet, so I created my own: Drag this link to your browser toolbar to get started:    Shorten with j.mp Technorati Tags: j.mp , bit.ly , tinyurl.com , twitter , Andrew Beacock

Summary of December's Manchester Spring User Group Meeting

The December Spring meeting was held on Tuesday 1st December at the same venue as previous meetings . Two talks were lined up: one on Grails by Adam Evans and one on Spring 3.0 by Rick Evans. Guy Remond of Cake Solutions started the evening off with introductions and explained that the Spring User Group was going to be expanding to become the 'Open Source Central User Group' so as to attract a more diverse audience. He also discussed the Open Source Central website which has plans to become the 'Hub for successful Open Source Enterprise Application Development'. It's going to pull various blogs together into one central place as well as offering video and podcasts of open source technologies. We were also some of the first people to get a physical copy of the Open Source Journal, a 5,000-copy print run (sponsored by Hays IT ). Practical Grails Demonstration by Adam Evans of CTI Adam started his presentation with a brief run through of what is Grails , w...

Paste Email Plus - perfect for multiple text snippets in Firefox

I've found recently when commenting on various blogs that I want to add a little footer to the comment with my name and blog address. For one or two comments typing it out by hand is fine but after a while I decided to try and find an automated way to deal with this issue. So I was looking for something that allows me to enter multiple lines of text and then very easily insert this text wherever I choose. Well I quickly found the perfect solution - a Firefox add-on called Paste Email Plus by Chuck Baker . You simply open the Paste Email Plus options window, enter a 'Label' to help identify this text, then enter the multi-line text in the 'Pastetext' field and click 'Save changes': You are now set up and ready to start pasting that text snippet, in any area where you would normally type text just right-click and select 'Paste Email Plus' (below 'Paste' on my system) and then choose your labelled snippet: You will now see your ...

JavaScript splits & matches with regular expressions (regex)

I had been developing some client-side validation code in jQuery / JavaScript and using Firefox (and the excellent Firebug ) to test and debug it. I was then asked to ensure that it worked in IE6 & IE7 and that's when the problems started. Apart from the usual "which file does that line number equate to, and why does it not tie up?" issues I found that IE doesn't like taking a regular expression as it's parameter to the JavaScript split function . Firefox will happily accept this and works fine but IE doesn't. After some searching it appears that Firefox might be the odd one out and that it's non-standard to pass in a regex. So what do you do if you want to split up a string based on a regular expression or rather a rule that can't be simply expressed in the way that the split function wants it? Wouldn't it be nice if you could ask if a string matches a regex but then use certain matched bits of the string in your next few lines of c...

A new way to label in GMail (and the end of Right-Sided Labels)

Back in March I blogged about my favourite GMail labs . One of them has died today - Right-side Labels . Google are grouping labels together with Inbox, Drafts, Chats and other system labels, and so putting the labels over on the right-hand side doesn't make sense anymore. The problem is, my GMail's not been updated yet so I can't play with the new features! :) Technorati Tags: Google , GMail , Google Labs , Andrew Beacock

Summary of June's Manchester Spring User Group Meeting

I missed the first Manchester Spring User Group meeting back in April which I heard was excellent so I made sure I didn't miss June's meeting . The sessions (based at the University of Manchester Core Technology Facility - cool building BTW) were organised by Cake Solutions (in particular their MD Guy Remond) and it was Guy that introduced the evening and laid out the agenda. Just a quick note about the venue, it's a very new tidy building, the room was an excellent size (seating for 50+ people) and coffee (and cake!) were provided. Parking was free and immediately outside the building, just press the buzzer and mention the Spring User Group... The first talk was by Paul Sweby (of CapGemini ) entitled: Spring in Government - Improving System & Personal Performance Paul works on the HM Revenue & Customs website and started his talk by providing some pretty impressive statistics: around 40 million tax payers use the HMRC web site for various purposes. The sof...

Easy, collaborative web UI mockups with Balsamiq

Every now and again you come across a tool that is so easy to understand, so fast to use and so effective at conveying it's ideas that you just have to tell people about it. One such tool is Mockups by Balsamic . It's a web page mockup drawing tool written using Adobe Air which provides a palette of HTML widgets with which to 'draw' your screens. It has a querky 'freehand' style which lends itself to conveying the components and ideas that a web page should have without forcing the designer to code it up in HTML (or for the customer to think that because the HTML is done, the app must nearly be ready...). Here is a very simple web page for search and listing users which I ' mocked up ' in less than 10 minutes: As you can see it's got a number of standard HTML widgets on it as well as a very useful 'post it' note allowing you to add distinctive notes and comments to the mockups themselves. So this in itself is enough to warrant using it to...

JSTL 'forEach' looping tricks using varStatus

Do you have a JSTL forEach loop in your JSP page displaying a list of results? Have you ever wanted to do something different for each row, or maybe do something for all but the last row? varStatus is what you want! You declare a new variable within the main forEach JSP block which will allow you to access the internal loop counter of the for-each loop. Then you can call a number of methods on that object to be able to do conditional processing. The code example below will display a horizontal rule under each item apart from the very last one: <c:forEach var="thing" items="${things}" varStatus="status"> <a href="${thing.link}">${thing.description}</a> ${not status.last ? '<hr/>' : ''} </c:forEach> The important bits of the above snippet are the varStatus="status" and status.last . The first one defines a 'status' variable, and the second one accesses it to ask if this...