<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gridshore &#187; jquery</title>
	<atom:link href="http://www.gridshore.nl/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gridshore.nl</link>
	<description>A weblog about software engineering, Architecture, Technology an other things we like.</description>
	<lastBuildDate>Tue, 13 Dec 2011 15:36:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Creating a sortable list of items using jQuery</title>
		<link>http://www.gridshore.nl/2009/09/14/creating-a-sortable-list-of-items-using-jquery/</link>
		<comments>http://www.gridshore.nl/2009/09/14/creating-a-sortable-list-of-items-using-jquery/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 23:01:01 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[sortable list]]></category>
		<category><![CDATA[spring 3]]></category>
		<category><![CDATA[spring framework]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=896</guid>
		<description><![CDATA[<p>For a project that I am working on Your-Scrum I need a lot of items in a list that are sortable. One Story is to have a backlog with stories that are sortable to reflect the importance. Using Domain Driven Design, I have created a rich domain model. Using the model, we can execute [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.gridshore.nl/wp-content/uploads/jquery-ui-logo.png" alt="jquery-ui-logo.png" border="0" width="258" height="74" align="left" />For a project that I am working on <em>Your-Scrum</em> I need a lot of items in a list that are sortable. One Story is to have a backlog with stories that are sortable to reflect the importance. Using <strong>Domain Driven Design</strong>, I have created a rich domain model. Using the model, we can execute all stories related to sorting items in a list. At the front-end I want an easy way to handle the sorting. I found a library for jQuery that can do the job for a large part on the client. Still there are some server side components as well.</p>
<p>The following screen gives an idea about the look and feel of the sortable list of stories.</p>
<p><a href="http://www.gridshore.nl/wp-content/uploads/Screenshot_yourscrum.png" rel="lightbox"><img src="http://www.gridshore.nl/wp-content/uploads/Screenshot_yourscrum.png" alt="Screenshot_yourscrum.png" border="0" width="200"/></a><span id="more-896"></span><br />
<h3>jQuery Sortable component</h3>
<p>Let us start to have a look at the front end. I am using jQuery together with jQuery-ui. Everybody doing series web development (should) know jQuery. I have written about jQuery before, but other have as well. Just do a search on google and the amount of articles is massive. Dzone also contains a few items each day about top 5 plugins for jQuery.  I think the power of jQuery-ui is not known that much. If you have not seen it before, be sure to check it out. It can help you a lot in creating websites that look sharp with icons and colors that are well balanced. The ui framework contains a lot of interaction components, widgets and effects. This blog posts focus is on the <a href="http://jqueryui.com/demos/sortable/">Sortable interaction component</a>.</p>
<p>With the sortable component you can actually drag the components in order. You get notified of the change.</p>
<h3>Setting op de component</h3>
<p>Before we can use the component we need to download the jquery-ui component. The jQuery UI project contains a <a href="http://jqueryui.com/download">download function</a> to create your customized download. Don&#8217;t forget to include at least the sortable function. You can also follow a long with the <a href="http://code.google.com/p/your-scrum/source/checkout">sources</a> I use in the your-scrum project. Now include the js files in your page. I use the script.js file to set generic libraries. (webapp/includes folder). Now open up the stories.jsp file under webapp/WEB-INF/jsp/story folder.</p>
<p>We begin by creating the list of items and use jQuery to make a sortable list out of it.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul id=&quot;sortable&quot;&gt;
    &lt;c:forEach items=&quot;${stories}&quot; var=&quot;story&quot;&gt;
        &lt;li id=&quot;story_${story.id}&quot; class=&quot;ui-state-default&quot;&gt;&lt;span class=&quot;listItemLabel&quot;&gt;${story.name}&lt;/span&gt;&lt;/li&gt;
    &lt;/c:forEach&gt;
&lt;/ul&gt;
</pre>
<p>Within the script block we now have to initialize the sortable component.</p>
<pre class="brush: jscript; title: ; notranslate">
var idsOldOrder;
$(function() {
    $(&quot;#sortable&quot;).sortable();
    idsOldOrder = $(&quot;#sortable&quot;).sortable('serialize').toString();
    $(&quot;#sortable&quot;).disableSelection();
    $(&quot;#sortable&quot;).bind('sortupdate', function(event, ui) {
        var ids = $(&quot;#sortable&quot;).sortable('serialize').toString();
        $.post('/story/reorder', {ids: ids, oldIds: idsOldOrder}, function(data) {
            // nothing special
            window.alert(data);
        });
        idsOldOrder = ids;
    });
});
</pre>
<p>This code might look more difficult than you did expect. That is because more is happening here than you expect. Within this code we need only the first line to show the sortable items. The other lines are for notification of changes. Don&#8217;t worry we explain them as well. Time to move on.</p>
<h3>Capturing change events</h3>
<p>Have a look at the previous code block. The second line stories a special form of presentation in a string. We need this on the server to actually determine the change. Than in line 4, we bind a function to the <em>sortupdate</em> event. Again a string containing the ids in the new order is created. Using the jQuery Ajax tooling we send a request to the server. The POST is done to the url <em>/story/reorder</em> with two parameters: ids and idsOldOrder. The result is shown in an alert box, which is not nice, but it works for now.</p>
<p>From the client side perspective, that is all there is to it. I actually wanted to have a real change from the library, like this item is moved before that item. But I could not find how to do just that. Therefore I had to do the trick with the old order and the new order. Now the server has to take care of finding the actual change. More on that later.</p>
<h3>Add task button</h3>
<p>One of the stories for our project is to add a new task to a story. If you have a look at the image containing a screen dump (the first image of this blog post) you see on each story the amount of tasks and an orange plus sign. The plus sign is something we use from the jquery-ui project as well. How to do this.</p>
<p>First we must add the content to the html using the jsp. So we have to extend the jsp with a text containing the number of tasks and a link that we can click to go to the add task form. The jsp now becomes:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul id=&quot;sortable&quot;&gt;
    &lt;c:forEach items=&quot;${stories}&quot; var=&quot;story&quot;&gt;
        &lt;li id=&quot;story_${story.id}&quot; class=&quot;ui-state-default&quot;&gt;&lt;span
                class=&quot;listItemLabel&quot;&gt;${story.name}&lt;/span&gt;&lt;span
                class=&quot;listItemAdd&quot;&gt;&lt;a
                href=&quot;/story/${story.id}/task/form&quot; title=&quot;add task&quot;&gt;&lt;spring:message code=&quot;generic.add&quot;/&gt;&lt;/a&gt;&lt;/span&gt;&lt;span
                class=&quot;listItemChilds&quot;&gt;tasks(${story.numberOfTasks})&lt;/span&gt;&lt;/li&gt;
    &lt;/c:forEach&gt;
&lt;/ul&gt;
</pre>
<p>Have a good look at the classes of the span elements. We are going to use them to change the appearance of the add link into that nice plus sign button. We are replacing the link with an image, clicking the image will call the function myClick which uses the actual link from the <em>a</em> element and opens that url. Have a look at the changes in the code.</p>
<pre class="brush: jscript; title: ; notranslate">
var myClick = function (event) {
    var location = $(event.target).children(&quot;a&quot;)[0].href;
    window.location = location;
};
$(function() {
    // only show changes, refer to previous code block for other lines
    $(&quot;#sortable li span.listItemAdd&quot;).addClass(&quot;ui-icon ui-icon-circle-plus&quot;).click(myClick);
});
</pre>
<p>Getting the icon with the plus sign is a jQuery trick as well. There are some style sheets that contain all the icons. You just need to find the right class to add to a span and you are done. I used the <em>ui-icon ui-icon-circle-plus</em>. More on the available icons can be found in <a href="http://jqueryui.com/themeroller/">the documentation</a>.</p>
<h3>Other jQuery things</h3>
<p>There are other things I use from jQuery. Check the references section for documentation. I use the corner plugin for the navigation. If you like the navigation implementation have a look at the main.jsp file in webapp/decorators. The final jQuery thing I want to mention is the <a href="http://code.google.com/p/js-hotkeys/">hotkeys plugin</a>. You can create hotkeys to be used on your page. I created a hotkey <em>ctrl+s</em> to open up the new story screen. The following code block shows the implementation.</p>
<pre class="brush: jscript; title: ; notranslate">
var newStory = function (event) {
    window.location = '/story/form';
    event.stopPropagation();
    event.preventDefault();
    return false;
};
$(function() {
    $(document).bind('keydown', 'ctrl+S', newStory);
});
</pre>
<h3>Finding the change on the server component</h3>
<p>The current status is that we have a POST to the server with two string containing ids in the old and the new order. Now we have to find the change. On the server I use Spring 3 to handle requests. I am not going to explain all the spring 3 configuration in this post. If you want to learn about spring 3 I advise you to go over the <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html">reference documentation</a>.</p>
<p>Handling the POST consists of two parts. The first part is finding the change from the two mentioned strings. The second part is communicate the change to the domain and persisting the change. In a next post I&#8217;ll focus more on the domain and the persistence part. For now have a look at the complete method that accepts the POST and handles it.</p>
<pre class="brush: java; title: ; notranslate">
    @RequestMapping(value = &quot;/story/reorder&quot;, method = RequestMethod.POST)
    public String reorderStories(@RequestParam(&quot;ids&quot;) String ids,
                                 @RequestParam(&quot;oldIds&quot;) String oldIds, ModelMap modelMap) {
        ItemSorter itemSorter = new ItemSorter();
        ChangedSortOfItems changedSortOfItems = itemSorter.determineChangeInStoryOrdering(strip(ids), strip(oldIds));

        Long movedItemId = null;
        try {
            if (StringUtils.hasText(changedSortOfItems.movedItem())) {
                movedItemId = Long.parseLong(changedSortOfItems.movedItem());
            }
        } catch (NumberFormatException e) {
            logger.warn(&quot;Number format exception of id from story to be planned while nog expected : &quot;
                    + changedSortOfItems.movedItem());
        }

        Long beforeItemId = null;
        try {
            beforeItemId = Long.parseLong(changedSortOfItems.beforeItem());
        } catch (NumberFormatException e) {
            logger.warn(&quot;NUmber format exception while nog expected&quot;);
        }
        backlogService.plan(movedItemId, BEFORE, beforeItemId);

        modelMap.addAttribute(&quot;message&quot;, &quot;story.order.changed&quot;);
        return &quot;message&quot;;
    }
</pre>
<p>This code should not be to hard to follow, now lets have a look at the <strong>ItemSorter</strong> class. This class uses the string to find differences. An instance of <strong>ChangedSortOfItems</strong> is returned that contains information about the items that have changed. In the end it is all about going through the list of items to find the first that changed from position. The first item that is different does not have to be the actual item that is moved. We can check that by looking at the next item. Have a look at the code if you can see what happens.</p>
<pre class="brush: java; title: ; notranslate">
    public ChangedSortOfItems determineChangeInStoryOrdering(String ids, String oldIds) {
        validateInput(ids, oldIds);

        if (ids.equals(oldIds)) {
            return ChangedSortOfItems.nothingChanged();
        }

        String[] arrayOfCurrentIds = StringUtils.delimitedListToStringArray(ids, delimiter);
        String[] arrayOfOldIds = StringUtils.delimitedListToStringArray(oldIds, delimiter);

        // A change must be found since the items are not equal
        ChangedSortOfItems change = null;
        int indexFirstChangedItem = findchangeInItems(arrayOfCurrentIds, arrayOfOldIds);
        // If you start at the beginning, the last item can never be the first item to change position
        String nextOfFirstChangedItem = arrayOfCurrentIds[indexFirstChangedItem + 1];

        if (nextOfFirstChangedItem.equals(arrayOfOldIds[indexFirstChangedItem])) {
            change = ChangedSortOfItems.movedBefore(arrayOfCurrentIds[indexFirstChangedItem],
                    arrayOfOldIds[indexFirstChangedItem]);
        } else {
            int lastitem = arrayOfCurrentIds.length - 1;
            for (int indexMovedBefore = indexFirstChangedItem; indexMovedBefore &lt; arrayOfCurrentIds.length;
                 indexMovedBefore++) {
                String movedItem = arrayOfCurrentIds[indexMovedBefore];
                if (indexMovedBefore == lastitem) {
                    change = ChangedSortOfItems.movedToEnd(movedItem);
                    break;
                } else {
                    String aNextOldItem = arrayOfOldIds[indexMovedBefore + 1];
                    if (!movedItem.equals(aNextOldItem)) {
                        change = ChangedSortOfItems.movedBefore(movedItem, aNextOldItem);
                        break;
                    }
                }
            }
        }
        return change;
    }
    private int findchangeInItems(String[] arrayOfCurrentIds, String[] arrayOfOldIds) {
        for (int i = 0; i &lt; arrayOfCurrentIds.length; i++) {
            String possibleMovedItem = arrayOfCurrentIds[i];
            String originalItem = arrayOfOldIds[i];
            if (!possibleMovedItem.equals(originalItem)) {
                return i;
            }
        }
        throw new NoChangeInSortFoundException();
    }
</pre>
<p>I hope the code is understandable. If not, questions can be asked in the comments <img src='http://www.gridshore.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<h3>Concluding</h3>
<p>Again I have to conclude that jQuery is a fantastic framework for client side development. I also have to conclude that the documentation and available samples are not always thorough enough. I am still not sure if there is no easier way to find the actual change. But maybe one of the readers of this blog out there can help me out. I do love the extendibility of the jQuery components.</p>
<p>If you liked this post, please push me up at dzone, if you have questions or remarks do not hesitate to use the comments.</p>
<h3>References</h3>
<ul>
<li><a href="http://code.google.com/p/your-scrum/">http://code.google.com/p/your-scrum/</a></li>
<li><a href="http://jqueryui.com/demos/sortable/">http://jqueryui.com/demos/sortable/</a></li>
<li><a href="http://jquery.malsup.com/corner/">http://jquery.malsup.com/corner/</a></li>
<li><a href="http://code.google.com/p/js-hotkeys/">http://code.google.com/p/js-hotkeys/</a></li>
<li><a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html">http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html</a></li>
</ul>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F09%2F14%2Fcreating-a-sortable-list-of-items-using-jquery%2F&amp;title=Creating%20a%20sortable%20list%20of%20items%20using%20jQuery&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/09/14/creating-a-sortable-list-of-items-using-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Start using jQuery with some small samples and using spring-mvc 2.5</title>
		<link>http://www.gridshore.nl/2008/01/24/start-using-jquery-with-some-small-samples-and-using-spring-mvc-25/</link>
		<comments>http://www.gridshore.nl/2008/01/24/start-using-jquery-with-some-small-samples-and-using-spring-mvc-25/#comments</comments>
		<pubDate>Thu, 24 Jan 2008 09:40:22 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Frontend Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[spring framework]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2008/01/24/start-using-jquery-with-some-small-samples-and-using-spring-mvc-25/</guid>
		<description><![CDATA[<p>This is a post about an ajax framework that was new to me. Not that it is a new framework, but I started seeing it in more and more places and they talked about it during the the springexperience as well. So I wanted to give it a go. I found out that there [...]]]></description>
			<content:encoded><![CDATA[<p><iframe src="http://rcm.amazon.com/e/cm?t=gridshore-20&#038;o=1&#038;p=8&#038;l=as1&#038;asins=1933988355&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr" style="width:120px;height:240px;margin:10px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" align="left"></iframe>This is a post about an ajax framework that was new to me. Not that it is a new framework, but I started seeing it in more and more places and they talked about it during the <a href="http://www.springexperience.com">the springexperience</a> as well. So I wanted to give it a go. I found out that there is a Manning Early Access Pogram book, so I bought it started reading and put some stuff in two sample applications I am creating:<br />
<a href="http://www.gridshore.nl/projects/raffleapp/">Raffle application</a>, this application demonstrates the following techniques : jpa/hibernate, springframework 2.5, and three different front end applications (wicket, gwt and spring mvc with jquery).</p>
<p><a href="http://www.gridshore.nl/projects/trainingoverview/">Training Overview</a>, this application used almost the same architecture as the raffle application. More focus on testing with and without the springframework, and jquery together with spring mvc 2.5</p>
<p>So what is it all about, that jQuery. To me it is a very easy to use light weight dom browsing framework with some very handy plugins. The architecture as been made to be very extendible. Let&#8217;s start with a very easy example:</p>
<pre>
$(document).ready(function() {
	$("#easysample").hide();
});

&lt;div id="easysample">Easy sample&lt;/div>
</pre>
<p>This sample shows a div and a piece of javascript (that should be positioned in the header within script tags). Right after the dom tree has been created and before it will  be shown, the function ready will be called. Within this function we do a search on the dom for an elemen called easysample. To the result we say hide. Easy does it. This is the first time I thought about the difference between creating the dom and making it ready to be shown on the screen. The normal javascript function onLoad in the body tag waits till the whole document is shown on the screen, which is pretty strange if you know up front that you are going to change it. Next to that it looks strange as well, it is a sort of flickr in the website when starting the page. So this is what $(document).ready is about. The second part starting with function () is the callback function. We provide the ready function with what we call a callback function. The event should call this function when it occurs.</p>
<p>This sample is a bid stupid, because you will get a blank screen. Let&#8217;s put a link in there that will help us show the div, hide it again, and keep a counter within the div showing the amount of times it was hidden. Here is the complete code:</p>
<pre>
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
&lt;head>
    &lt;title>Easysample&lt;/title>
    &lt;script type="text/javascript" src="js/jquery-1.2.1.min.js">&lt;/script>
    &lt;script type="text/javascript">
        var clickTimes = 0;
        $(document).ready(function() {
            $("#easysample").hide();
            $("#togglelink").click(function() {
                $("#easysample").html("Easy sample : clicked " + ++clickTimes + " times").toggle();
            });
        });
    &lt;/script>
&lt;/head>
&lt;body>
    &lt;span id="togglelink">Click me&lt;/span>
    &lt;div id="easysample">Easy Sample&lt;/div>
&lt;/body>
&lt;/html>
</pre>
<p>Again right after the document model is ready we hide the div and we assign a callback function to the click event of the span. The function html sets the provided text as the contents for the element that was found. The toggle function toggles between hide and show. You can find a running version of the sample <a href="http://www.gridshore.nl/samples/jquery/easysample.xhtml">here</a>.</p>
<p>Just like hiding and showing, we an also toggle styles. Have a look at the following example code. I&#8217;ll only show the document ready part:</p>
<pre>
$("#togglelink").click(function() {
    $("#easysample").html("Easy sample : clicked " + ++clickTimes + " times").toggleClass("attention");
});</pre>
<p>You can find a running version of the sample <a href="http://www.gridshore.nl/samples/jquery/easysample2.xhtml">here</a></p>
<p>So we know how to identify an element, know how to show and hide it, can change the contents and can add style. The mentioned book covers a lot more of course, there is a lot to be said about the whole event model. This model is not very consistent across all browsers. jQuery makes it a lot easier to do. For me two other things were very important: Making things look nice without to much effort and doing some ajax. Let&#8217;s have a look at that.</p>
<p>For visual effects we will use a plugin that is supported by the jQuery team called UI, yes cool isn&#8217;t it? You can find more information at <a href="http://ui.jquery.com/">there website</a> with some cool demo&#8217;s. I like the sortable table plugin. Not that I did not see more fancy scripts, and actually I am missing a filter option, but I&#8217;ll have a look at that the coming weeks. Take a look at the following code. I do not present the whole html code mode you will understand what happens. Before you can use this yourself, read about the stylesheets, the images etc. You do need to include the javascript with the table stuff in there, you need to include some styles and three images there are referenced by the style sheet.</p>
<pre>
    &lt;link rel="stylesheet" type="text/css" href="styles/flora.tablesorter.css"/>
    &lt;script type="text/javascript" src="js/jquery-1.2.1.min.js">&lt;/script>
    &lt;script type="text/javascript" src="js/jquery.tablesorter.pack.js">&lt;/script>
    &lt;script type="text/javascript" src="js/jquery.tablesorter.pager.js">&lt;/script>
    &lt;script type="text/javascript">
        $(document).ready(function() {
            $("#datalist")
                    .tablesorter({sortList:[[2,0],[3,1]], widgets: ['zebra']})
                    .tablesorterPager({container: $("#pager")});
        });
    &lt;/script><br/>
    &lt;table id="datalist" class="tablesorter">
        ...
    &lt;/table>
</pre>
<p>A lot of the nice stuff is handled in the stylesheet. Please take a look at the online sample <a href="http://www.gridshore.nl/samples/jquery/tablesample.xhtml">here</a>. The above code shows the two additional scripts to load (beware, I had to download the most recent versions which can be found <a href="http://tablesorter.com/docs/">here</a>). We also need to load a stylesheet, I took the one from the ui.query homepage. For the pager stuff you need to add an additional div and some icons. Download the complete package from the website and you will find the required resources. There is one thing I want to mention as well. The tablesorter function accepts a sortList parameter. This sortList is an array of arrays. Where the inner arrays contain two numbers, the first represents the column (starting at zero), the second reopresents the sorting. A zero for sorting means ascending and 1 descending. These are used as deafults when the table is creted.</p>
<p>We are almost at the end of my introduction. The final thing to show is some ajax to call the server. The sample will come up with a table that has some clickable fields. By clicking on the field you will obtain detailed information about the field from the server. For now the detailed information is coming from a php page and that is not working for me. But the general concept stays the same. You can find the running sample <a href="samples/jquery/tableajaxsample.xhtml">here</a>. The most important part of the code is in the next code block.</p>
<pre>
    &lt;script type="text/javascript">
        $(document).ready(function() {
            $("#datalist").tablesorter({sortList:[[2,0],[3,1]], widgets: ['zebra']});
        });
        function details(name) {
            $("#detailscontent").load("persondetails.php", {personname : name}, function() {

            });
        }
    &lt;/script>
    &lt;body>
    ...
        &lt;tr>&lt;td>&lt;a href="#" onclick="details('jettro')">Jettro&lt;/a>&lt;/td>&lt;td>35&lt;/td>&lt;td>1.80&lt;/td>&lt;td>male&lt;/td>&lt;/tr>
    ...
        &lt;div id="detailscontent">Details&lt;/div>
    &lt;/body>
</pre>
<p>The detailscontent div is used to present the new obtained data. Within the link we call a javascrip, deatils. This javascript does load the new content for the div. This piece of code is all there is to it:</p>
<pre>
$("#detailscontent").load("persondetails.php", {personname : name}, function() {});
</pre>
<p>The function accepts the page to load (persondetails.php), the parameters to pass to the server using the request object ({personname : name}) and finally a callback function, which we do not use in the sample.<br />
For another application I am creating (you cannot see this live, but you can see the code), I am also using this technique. In this application I am talking to a spring-mvc 2.5 application. You can find the maven generated site <a href="http://www.gridshore.nl/projects/trainingoverview/">here</a> (same as the one at the beginning of this blog item. You can find the complete code of this application in <a href="http://gridshore.googlecode.com/svn/trunk/TrainingOverview/">google code</a>. The following piece of code should look familiar by now. It is called after clicking a link and it calls the url projectemployees.view with the parameters projectId.</p>
<pre>
        function fillEmployeesBox(projectId) {
            $("#employeesBox").load("projectemployees.view",{projectId : projectId}, function() {
                $(".zebra tr:nth-child(even)").addClass("striped");
                $("#employeesBox").show();
            });
        }
</pre>
<p>Hope you liked this short introduction into jquery. There are a lot of resources to be found on the web. Of course the jquery homepage <a href="http://jquery.com/">http://jquery.com/</a> is a very good place to start. And I have shown a book which helps me a lot during my jquery programming.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2008%2F01%2F24%2Fstart-using-jquery-with-some-small-samples-and-using-spring-mvc-25%2F&amp;title=Start%20using%20jQuery%20with%20some%20small%20samples%20and%20using%20spring-mvc%202.5&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2008/01/24/start-using-jquery-with-some-small-samples-and-using-spring-mvc-25/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

