Skip to main content

Posts

Showing posts from April, 2010

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

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 signature! 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 coll