Thursday, October 27, 2011

So LWUIT does that too?

I was recently developing a mobile app with the LightWeight UI Toolkit (LWUIT) that required me to save state in a database of some sort on the mobile phone and I didn't want to go in the way of manually saving bytes with the Record Management Store (RMS), so I opted for Floggy - a free object persistence framework for J2ME/MIDP applications. The main goal of this framework is to abstract the data persistence details from the developer, reducing the development and maintenance effort. In the process of reading up on Floggy, I stumbled on an old post by Shai where I discovered that LWUIT IO already has most of the persistence functionalities I need. So if at any time you need to go a little above what RMS offers, you can try out LWUIT IO, but if you'd rather not use LWUIT at all, you can give Floggy a trial instead.

Subscribe to the NEW Java Magazine

Java Magazine (1st Issue)

Oracle has just released a digital and mobile format of Java Magazine. Java Magazine will be published on a bi-monthly basis in digital and mobile formats and is an essential source of knowledge about Java technology, the Java programming language, and Java-based applications for people who rely on them in their professional careers, or who aspire to. You can sign up today here to stay informed on all things Java!

Thursday, October 20, 2011

Interesting JavaOne 2011 Content Slides and Catalog, Part 2

Here's the continuation of some interesting JavaOne 2011 tracks:

Java ME, Mobile, Embedded and Devices

Java SE, Client Side Technologies and Rich User Experiences

There are still quite a lot more interesting ones too numerous to list. You can peruse the whole catalog here. Sun in those days used to make available all the content catalog and slides as a single archive, but it seems Oracle would rather have you download them one by one in different windows.

Interesting JavaOne 2011 Content Slides & Content Catalog

The Content Catalog for JavaOne 2011 is available here. You can use the fields provided to narrow down your interest, or if you'd rather peruse the available tracks, just select the track you are interested in from the drop-down and then click the search button. When the list of sessions are displayed, click the PDF icon at the right-hand-side to download the associated slides for the session.

Here are the links to the slides (PDF) of the ones that caught my fancy:

Core Java Platform


(to be continued)

Ooops, but I didn't check this item.

It is always very important to read the changelog of libraries which you occasionally put to use. I would have spent the whole day trying to figure out why my checkbox selections weren't working well but luckily enough, I read through the changelog of jQuery 1.6 a few days ago, so immediately I discovered my checkboxes selections weren't being detected properly in the code, I knew who the culprit could be.

I recently modified some sections of a client website to use jQuery 1.6 because of the .data() method introduced in jQuery 1.5, which allows you to automatically import any data- attributes that were set on the element and convert them to JavaScript values using JSON semantics. This makes it easy to store the data you'd be using later on the node itself rather than parsing the DOM later to extract it. This feature also received a major change in the way it works in jQuery 1.6. In jQuery 1.6, this feature has been updated to match the W3C HTML5 spec with regards to camel-casing data attributes that have embedded dashes. So for example in jQuery 1.5.2, an attribute of data-max-value="15" would create a data object of { max-value: 15 } but as of jQuery 1.6 it sets { maxValue: 15 }.

Before jQuery 1.6, you can check if a particular checkbox is checked with $('#myCheckboxID').attr('checked') but that no longer works as expected in jQuery 1.6+. Previously, .attr("checked") returned the Boolean property value (true) but as of jQuery 1.6 it returns the actual value of the attribute (an empty string), which doesn’t change when the user clicks the checkbox to change its state.

In code that uses jQuery 1.6 or newer, the new method $(this).prop("checked") retrieves the same value as this.checked and is relatively fast. Finally, the expression $(this).is(":checked") works for all versions of jQuery.

So all I had to do was to change my previous code from $('#myCheckboxID').attr('checked') to $('#myCheckboxID').prop('checked'). If not that I had read the changelog earlier, I probably would have spent the whole day chasing around an unknown bug in my code.

Sunday, October 16, 2011

Hey ma'am, where are my cookies?


I recently made some big changes to a content management system I built for one of my clients about 5 years ago. I worked on the site's SEO, enabled clean URLs via .htaccess files because the CMS wasn't built with MVC where there would probably have being a main controller that routes requests to others.

The problem started after I had added all the necessary pages but spent the next few days worrying about a bug in one of my scripts, as the cookies added on some pages of the site do not propagate to other pages. Looking through Chrome Developer Tools and Firefox's Firebug, I could see all the cookies, but when I fetch the cookies via document.cookie, I only get to see some of the cookies and not all. I wondered why a script that was perfectly working before changes to it's routing stopped working. I spent several days modifying my script that manages cookies only to discover after almost a week of battling with it that you should think twice before leaving the path property of a cookie blank when creating it.

When you leave the path property of a cookie blank, it means that only websites in that domain (including the path) that set the cookie can retrieve it. For example, if you create a cookie on the page www.mywebsite.com/books and left the path property blank, it wouldn't be accessible from www.mywebsite.com/novels because the path for the created cookies are /books but you are trying to access it from /novels. So, to avoid unnecessary headache while managing cookies in your application or on your website, ensure that you set the path to the root .i.e. '/', instead of leaving it blank if you want it to be accessible from all paths within that domain.

The culprit in my case was:
document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");

but I eventually overcame the problem by modifying the path of any created cookies to be '/' instead of leaving it blank as obtainable above.
document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "/") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");

This StackOverflow answer saved my ass . You can read more about cookies here.

Where have you been?

It's been quite awhile since I last put up a post on this blog. I planned turning a new leaf earlier in the year but somehow couldn't as my engagements and activities kept me busy all throughout the year. There were lots of times I had a developmental challenges and plan posting the solutions I used to overcome the problems, but I just kept procrastinating all along. It was just today I decided to do it no matter what.

To start with, how has been the year so far? Beautiful I hope. Well, it has been beautiful for me too, though it wasn't without the usual ups and downs, but we however thank God we're still standing. We almost lost one of houses completely, earlier in the year as one of the tenants raised down two out of four flats with fire and disappeared into thin air, but we thank God for his mercy and faithfulness.

Was contacted earlier in the year by Microsoft via LinkedIn to send in my CV and fill the skills self-assessment document they sent to me. I had to let the Staffing Lead for MEA Services Recruitment know that I was more of open-source than closed source and last worked actively with some of their technology stacks over 3 years ago while I was at Quanteq, but they however still wanted me to go ahead and send my details. Funnily enough, I'm not even well versed with Windows 7. Seems I rated myself a 2/10 or 3/10 as I had not used the OS for more than probably 3 hours since it came out. It's not like I can't do serious stuff with it, but I've not dissected apart the way I've done with Windows XP, which is still what I use on my desktop machine. Whatever I can do on it would be with the knowledge I have with Windows XP. My OS of choice since the last two years has been Apple's Mac OS X. Anyway, the long and short of it is that the recruitment never pulled through as they needed someone with stronger MS Technical skills :)

However, if you think you have what it takes to do great stuff with Microsoft stack of technologies and would like to work with them, do contact me and if convinced, I'd forward your CV to the Staffing Lead for MEA.

It was a pity we lost our dear Steve Jobs. I never had the opportunity to meet him and never really dreamt of meeting him, but I must confess that he's touched my life in so many ways even though our paths have never crossed and beyond me being an apple fan-boy, of which I'm not one, I just love the way their products ooze cool and deliver beyond your expectations, even though my last iPod-Touch didn't last more than 3 months before it gave up the ghost. He touched our lives in so many personal, delightful & emotional ways, kept everyone on their toes & totally disrupted the industry leaving behind a few casualties. Android wouldn't have gotten this far if it hadn't been for SJ and his team, and the best Android phone today - Samsung Galaxy S II, would have had no one to steal ideas from. I couldn't control the tears as it dropped when I read the news around 3.30am the day after his death. Steve, though we never met, you were one of my greatest inspirations. Thanks for thinking different. Adieu!