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:

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

Trying to get the value entered into the input box was failing, this is what I was trying:

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:
See the jQuery FAQ for more details.

Technorati Tags: , ,

Great tip regarding annotated Spring form validation & BindingResult

Found an interesting little gotcha at work last week, I was adding form validation to an annotated Spring controller, creating a custom Validator to do the work and wiring it in to the controller's method signature with the use of the BindingResult parameter (I just tacked it on the end of my existing parameters):

@RequestMapping(method=RequestMethod.POST, params="action=person")
public String createPerson(@ModelAttribute("person") PersonForm person, ModelMap model, BindingResult result) {
    // code goes here...
This resulted in a slightly odd error message:
java.lang.IllegalStateException: Errors/BindingResult argument 
declared without preceding model attribute. Check your handler method 
I was a little confused by this message, it was indicating that I didn't have the form's model attribute declared before the BindingResult but I certainly have. After some google searching for this error message I found a website created by a colleague of mine (Mark Lishman) which had just the answer that I needed:
The BindingResult parameter must be positioned directly after the corresponding model argument that is being validated.
Taken from the information tip box on the Level Up Spring MVC Form Validation page.
So basically it meant that my controller method should have been this:
@RequestMapping(method=RequestMethod.POST, params="action=person")
public String createPerson(@ModelAttribute("person") PersonForm person, BindingResult result, ModelMap model) {
    // code goes here...
Level Up is an excellent resource for people starting out with Spring, Hibernate & Oracle, check it all out at the Level Up website.

Technorati Tags: , , , , ,