Spring Interceptors

To add an interceptor to your application, do the following;

Add the following to your application-context.xml file;

<context:component-scan base-package="com.test" />

<mvc:annotation-driven/>

<mvc:interceptors>
	<bean .... />
</mvc:interceptors>

http://forum.springsource.org/showpost.php?p=289544&postcount=4

Spring-EL Expressions

To enable spring security EL expressions, add the following to the <http> element in your application-security.xml file;

use-expressions="true"

A few gotcha’s when enabling this; each of your <intercept-url … role=”ROLE_USER” needs to be changed to role=”hasRole(‘ROLE_USER’)

Also – the following exception will be thrown unless you change ‘IS_AUTHENTICATED_ANONYMOUSLY’ to ‘permitAll’;

Failed to evaluate expression 'IS_AUTHENTICATED_ANONYMOUSLY'

In your JSP pages the following can be used for securing portions of pages;

<sec:authorize access="hasRole('ROLE_MANAGER')">
...
</sec:authorize>

A few other useful links;

http://static.springsource.org/spring-security/site/docs/3.0.x/reference/springsecurity-single.html
http://ambisoft.pl/blog/

Spring – c:foreach and hibernate’s maps / lists

iterating over a list / set can be done via;

<c:forEach items=”${job.jobPhotos}” var=”photo” varStatus=”idx”>
<form:hidden path=”jobPhotos[${idx.index}].id” />

Iterating over a map can be done via;

<c:forEach items=”${job.jobPhotos}” var=”current”>
<form:hidden path=”jobPhotos[${current.key}].id” />

${current.key} and ${current.value.id} are equilivant (both equate to the ID of the row being iterated over)

http://www.steve-farmer.com/examples/jstl/ui/c-foreach-map.jsp
http://blog.vergiss-blackjack.de/2010/04/iterating-over-nested-objects-in-a-spring-form/

Hibernate Annotations – Bidirectional One-To-Many

Spring Date / time parsing

Here’s a few ways to format datetime / date / time values via spring;

Use the @DateTimeFormat annotation to specify the format Date values need to be displayed in. Style comes in a few flavours (see the link at the bottom), and pattern uses the standard java pattern for formatting.

http://www.developer.com/java/web/article.php/3879471/Spring-Framework-30-and-Annotation-driven-Formatting.htm

jQuery Book – Basics through to Performance Optimisations

A few things to note;

  • When using selectors with ID tags, use $(‘#abc’).find(‘.defg .higk’); instead of $(‘#abc .defg .higk’);
  • Also use named functions more-so than anonymous ones;
    var PI = {
    onReady : function() {
    $(‘#magic’).click(PI.candyMtn);
    $(‘#happiness’).load(PI.url + ‘ #unicorns’, PI.unicornCb);
    },
    candyMtn : function(e) {
    $(‘#yayeffects’).slideUp(PI.slideCb);
    },
    slideCb : function() { … },
    unicornCb : function() { … }
    };
    $(document).ready(PI.onReady);
  • Plugin creation;
    // defining the plugin
    (function($){
    $.fn.hoverClass = function(c) {
    return this.hover(
    function() { $(this).toggleClass(c); };
    };
    }(jQuery);// using the plugin
    $(‘li’).hoverClass(‘hover’);
  • see here for signs of poorly written plugins; http://remysharp.com/2010/06/03/signs-of-a-poorly-written-jquery-plugin/
  • See here for details on plugin development; http://www.learningjquery.com/2007/10/a-plugin-development-pattern

http://www.rebeccamurphey.com/jqfundamentals/book/release/html/

jquery-fundamentals-book