Java Hibernate ManyToMany Tutorial – With Add and Delete examples

The many-to-many mappings and usage thereof can be a little bit weird on first glance.

This tutorial demonstrates:

  1. The mappings (Annotations not XML).
  2. Adding an entity to a group.
  3. Removing an entity from a group.
  4. Listing parents with children.
  5. Listing children with parents.

image

(The Hibernate Logic is completely separate from the UI)

The project is available to download at the bottom of this post.

Continue reading “Java Hibernate ManyToMany Tutorial – With Add and Delete examples”

CSS – Removing the (new-line) spaces between inline elements

image

Observe the gap between the checkbox and the label on the second instance!

This is a “feature” with inline (or inline-block) elements on a page. A new-line /carriage-return in the code is treated as white space between inline elements.

While good advice would be to work with this rather than against it as someone mentioned on stackoverflow; there are still times when you need to get rid of the spaces.

Continue reading “CSS – Removing the (new-line) spaces between inline elements”

Flexible Size, Flexible Color Icons for jQuery-UI

Different Icon Size, Different Icon Colors for jQuery-UI
Different Icon Size, Different Icon Colors for jQuery-UI

Achieving different size, different color icons in jQuery-ui and non-jQuery-ui web apps.

This tutorial reveals how FontAwesome icons can be used rather than trying to resize existing jQuery-ui icons.

I initially wanted jQuery-UI icons to be available in different sizes, for example:

<span class=”ui-icon ui-icon-pencil”></span> A Pencil Icon (existing)

<span class=”ui-icon ui-icon-pencil large red”></span> A large, red Pencil Icon (ideal, read on…)

The solution I found does not require jQuery or jQuery-UI but works perfectly seamlessly with it regardless.

Continue reading “Flexible Size, Flexible Color Icons for jQuery-UI”

jQuery-UI : change the color of a button using CSS classes

In many web applications it’s necessary to have more than one color button, primary and secondary for example.

Changing the color of jQuery-UI buttons using CSS
Changing the color of jQuery-UI buttons using CSS

This tutorial demonstrates how to achieve this using only CSS.

Continue reading “jQuery-UI : change the color of a button using CSS classes”

jQuery-UI : Specifying different Button Icon colors using only CSS classes

Doing this:

Results in

Specifying Button Icon colors using CSS only rather than using custom JavaScript
Specifying Button Icon colors using CSS only rather than using custom JavaScript

This tutorial demonstrates how changing the icon color can  be achieved.

Continue reading “jQuery-UI : Specifying different Button Icon colors using only CSS classes”

jQuery-UI : Applying an Icon to a button using CSS classes

This tutorial simply demonstrates a generic reusable JavaScript snipped which will allow you to specify Button Icon’s using only CSS classes. I.e. no need to apply Icons using JS anymore.

Adding icons to buttons using CSS only
Adding icons to buttons using CSS classes in the same way as using icons in general

Continue reading “jQuery-UI : Applying an Icon to a button using CSS classes”

jQuery-UI : Changing the color of an icon

This quick tutorial demonstrates how to change the color of jQuery UI icons.

e.g.

changing the color of jQuery-UI icons
different colored jQuery-UI icons

will result in red and blue icons respectively

Continue reading “jQuery-UI : Changing the color of an icon”

Spring 3 MVC – Adding Objects to a List element on the fly at form submit – (Generic method)

Edit 10-Feb-2015

A much better approach to this problem is simply to use JSON. A number of comments below are in regard to nested lists. The solution detailed here does not readily facilitate nested lists. The solution outlined in this blog does: http://outbottle.com/spring-4-web-mvc-json-handling/. JSON is the recommended way of achieving “Adding Objects to a List element on the fly”

End Edit

Edit 12-Feb-2015

Alternatively, this blog also demonstrates the solution:

Spring 4 Web MVC with AngularJS

Abstract

The project downloadable below is an answer to a question repeated in this blog (Spring 3 MVC – Adding Objects to a List element on the fly at form submit – (Generic method))

“How can I submit nested lists of objects?”

The answer is AJAX and JSON.

A very good approach to this is with AngularJS and Spring as demonstrated here.

End Edit

 

ok, hard to describe this one and hard to find stuff on google so here’s an image explaining.

Add and Remove Items from List Dynamically in Spring 3 Web MVC
Add and Remove Items from List Dynamically in Spring 3 Web MVC

When clicked, the ‘Add’ and ‘Remove’ links in the image generate JavaScript events which add and remove the HTML elements dynamically client-side. The idea is to allow a Java List Object to have elements added and removed dynamically on form submission.

A Generic JavaScript library is provided. It makes the process of dynamically adding List elements (rows or Person objects in this example) effortless for any situation. The JavaScript library provides callabacks thus facilitating an AJAX implementation with little effort.

The Netbeans project and the JavaScript file are available for download at the bottom of the page.

Continue reading “Spring 3 MVC – Adding Objects to a List element on the fly at form submit – (Generic method)”

Hello Spring 3 Security with Netbeans – Role Based Method Protection

This tutorial will outline in simple steps how to do the following:

  1. Create Spring 3 Web MVC project using Netbeans
  2. Introduce Spring Security measures
  3. Limit @Controller method invocation to certain User-Role’s using Annotations
  4. Roles and users are defined within XML configurations.
  5. The full source code is available for download here

Continue reading “Hello Spring 3 Security with Netbeans – Role Based Method Protection”

Custom Annotated Validation with Spring 3 Web MVC

My previous tutorial detailed using Hibernate Validation within Spring 3 Web MVC.  This tutorial shows how to create custom validation annotations.

E.g.

This example annotation only permits the word ‘John’. Optionally, it can be case-sensitive.  Continue reading “Custom Annotated Validation with Spring 3 Web MVC”

Spring 3 Web MVC – Exception Handling – incorporating AJAX

Spring 3 Web MVC Exception Handling with AJAX
Spring 3 Web MVC Exception Handling

This tutorial demonstrates how to handle exceptions in Spring 3 Web MCV.
Emphasis is given to Handling  exceptions that occur during AJAX requests. I.e. in the event of an exception during an AJAX request,  it is not desirable to redirect to an error page, instead JavaScript error handling code should be invoked with relevant information passed in.

 

A Netbeans project is available for download at the bottom of this page.

Continue reading “Spring 3 Web MVC – Exception Handling – incorporating AJAX”

Integrating Hibernate with Spring 3 Web MVC

This tutorial on “Integrating Hibernate with Spring 3 Web MVC” incorporates:

  1. Hibernate Transaction Control
  2. @RequestMapping friendly URL’s. More on this specific Spring 3 Web MVC friendly URL topic here. (Alternative @RequestParam method here)
  3. A Generic DAO suitable for Hibernate operations with Spring 3 Web MVC. More here in this separate Generic DAO tutorial.
  4. Spring 3 Web MVC Dependency Injection (DI) and Inversion  of Control (IoC). More on DI and IoC here.
  5. Netbeans (7.1.1 used here but any version will do)

The complete Netbeans project is available for download here. The SQL for the project is included in the download in the WEB-INF folder.

Update: Jan 8, 2014

———–

The project originally available for download does not work with Netbeans 8 due to libraries that were in Netbeans 7.1.1 no longer available in Netbeans 8. Additionally, a comment below referencing Netbeans 7.0 .1 may suggest the same problem. This enforces the point that a dependency management utility is a much better means of building projects. To that end this project has been recreated using Maven. This ensures it will work irrespective of IDE version. In fact because it’s a maven project it’s not dependant on an IDE at all. It should work on any IDE that supports Maven. Netbeans of course, does support Maven. Here is the download link SpringHibernateCrudMvn for the Maven version of this application.

The POM is quite comprehensive in that it includes support for Spring, Spring-Security, Jackson, Hibernate, Hibernate-search and a bunch of other utilities. It can serve as a template to a certain extent.

—————————————————— (/End Update)

Continue reading “Integrating Hibernate with Spring 3 Web MVC”

Setting the Welcome Page in Spring Web MVC

In any Spring Web MVC application, there is a need to set the default landing or welcome page.

Traditionally in Java web applications, this is done in the web.xml file as so:

Or in a spring web mvc application, it might be like this:

With a corresponding controller class RequestMapping:

 

This is ok, because “/” is a valid existing URL but, if the required welcome page is to be a virtual URL such as /person/list a little more creativity is required.
Continue reading “Setting the Welcome Page in Spring Web MVC”

Determining the primary key property name using Hibernate

Simple method:

String idPropertyName = sessionFactory.getClassMetadata(User.class).getIdentifierPropertyName();

To get the actual value see this tutorial

Elaboration
Continue reading “Determining the primary key property name using Hibernate”