Something that would have helped me a lot would have been an example that includes a full Spring / Acegi setup, packaged with Maven so it works 'out of the box', including a couple of screens that actually does your regular search / crud operations. So, I've decided to extract such an example from a project I've been working on. This is just my tiny contribution to the ZK community.
This example app includes all of the above, as well as using Hibernate for persistence, though that is all wrapped in Spring and accessed via services. It's far from perfect, but I think it's a good start. I would greatly appreciate any feedback or suggestions if anyone uses this.
Download:
Download the project as a ZIP file from here.
Usage:
When you launch, you will be presented with a login screen. The Acegi setup is such that a hard-coded user 'admin' with password 'password' can log in only until an actual user exists in the database. The system has screens for administering users, roles and privileges.
Initial setup:
Firstly, you will need Maven, Java, and a database. The example application uses PostgreSQL. To use a different DB setup, edit the following files:
- zkskeleton-persistence/pom.xml (The driver from Maven)
- zkskeleton-datasource-context.xml (Connection when deployed)
- zkskeleton-domain-test-context.xml (Connection for integration tests)
CREATE USER zkskeleton WITH PASSWORD 'zkskeleton' createdb nosuperuser;To get it running:
CREATE DATABASE zkskeleton WITH OWNER = zkskeleton;
\c zkskeleton
CREATE SCHEMA zkskeleton AUTHORIZATION zkskeleton
- Unpack it somewhere
- mvn clean install
- Deploy the WAR from zkskeleton-web/target/zkskeleton.war
I use idea, but eclipse is pretty similiar
- mvn idea:clean idea:idea -DdownloadSources=true
- Open the project file
The first thing you'll probably want to change is the name, to do this refactor all the packages from 'zkskeleton' to something appropriate. You will also need to change the project directories and xml file names. Then do a global search and replace from 'zkskeleton' to your application name. You will probably also want to change the DB setup, this can be done as explained above.
Architecture:
Of course there are lots of clever ways to do this, but my architecture looks something like this:
- Domain layer depending on nothing, containing the domain entities
- Persistence layer depending on Domain, containing Hibernate crud stuff
- Service Shared layer depending on Domain (bad thing, but I can live with it for purely web based) containing service interfaces and DTO's
- Service depending on Service Shared containing service implementations
- UI layer depending on Service Shared containing ZK classes, controllers and extensions
- Web layer depending on Service and UI, containing the ZK markup files, webapp setup, and Acegi and service wiring.
PS: The idea behind the navigation is borrowed from the ZK demo app, I hope they don't mind. Since that source is freely available it's probably fine, just giving credit where it's due though.