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

Iterating over nested objects in a Spring form

Hibernate Annotations – Bidirectional One-To-Many

Sweet-sour chicken

Serves 4

Ingredients;

  • 2 small carrots, very thinly sliced
  • 1 small green pepper, de-seeded & cut into small strips
  • 4 level teaspoons finely-chopped canned pineapple
  • 6 spring onions or shallots, chopped
  • 4 tablespoons syrup from can of pineapple
  • 1 tablespoon soy sauce
  • 1 level tablespoon  clear honey
  • 1 oz (25gm / 1 teaspoon) brown sugar
  • 4 tablespoons vinegar
  • 2 level tablespoons cornflour
  • 1/2 pint (250ml – 1  cup) chicken stock
  • salt & pepper
  • 1 oz (25gm) flaked blanched(white) almonds
  • 1oz (25gm – 1/2 teaspoon) butter
  • 1 freshly-roasted chicken (1 + 1/2 kilo)

Method;

  1. put carrots into saucepan with green peper, pineapple & spring onions
  2. Stir in pineapple syrup, soy sauce, honey, sugar and vinegar
  3. Slowly bring to boil and simmer for 5 mins
  4. Meanwhile, blend cornflower to a smooth cream with the chicken stock
  5. Add to saucepan and cook, storing until sauce comes to the boil and thickens. Season with salt & pepper. Add almonds and butter. Leave over very low heat.
  6. Quickly cut the chicken into bite-size pieces and put into a warm serving dish
  7. Coat with sweet-sour sauce and serve straight away with freshly boiled rice or noodles

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

Chocolate, Prune & Walnut cake (incomplete)

Ingredients

  • 250 gm pitted prunes
  • 3 tbsp cognac / brandy
  • melted butter for greasing the form/mould
  • 3 tbsp flaked almonds to prepare form (to sprinkle on form to make sure the cake doesn’t stick to the form)
  • 4 eggs
  • 1 + 1/4 cups caster sugar
  • 1 tbsp finely grated lemon rind
  • 1 + 1/4 cups thickened cream
  • 2 cups self raising flour
  • 1 cup walnuts
  • icing sugar for dusting
  • 3 tbsp cherry jam
  • cocoa

Method;

  1. cut up & soak them prunes in brandy
  2. dust tin with melted butter and sprinkle flaked almonds
  3. beat eggs with castor sugar and lemon rind until thick & pale
  4. stir in cream & gently fold in flour
  5. remove about 1/3rd of the mixture
  6. combine jam & cocoa, plums and walnuts and stir into remaining mixture
  7. spoon into prepared mold
  8. pour plain mixture into mold
  9. stir with knife to get marbled effect

(need a few last steps here…)

Cooking steaks…

Steak (300g sirloin)

Medium heat
Drizzle with olive oil
Sprinkle with sea salt & pepper
8 min – medium rare (4 min each side, rotate 90 degrees each 2 min)
16 min – medium
32 min – well done

After cooking, brush with oil & thyme
Sprinkle with sea salt

Rare

– lean cut (eg. eye fillet)

season with salt & pepper over medium-hot grill
3-4 mins on each side

Medium

t-bone
4 mins on each side
rest for at least 2 mins

Well done

rump steak
salt & peper
when firm to touch take off grill
should be grey-brown all through

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