| Subcribe via RSS or via Email

Expanded Wicket Component Expressions

November 22nd, 2009 | No Comments | Posted in Java, Wicket

I have updated my wicket component expressions library to include enabled and visible conditions in the expressions.

This basically means that you can filter your component expression by if a component is visible, enabled, or both. The following is an example of what can now be done:

"one1[enabled=true]:two1[enabled=true]"
"one1[visible=true and enabled = true]:
                 two1[visible=true & enabled=true]"
"**[visible=true]"

As before the code is available on the london wicket google code project, under an apache 2 licence. Due to the additional functionality I have bumped up the version number to 0.2.0, so you will need to update you pom to reflect this.

Tags: ,

Wicket Component Expressions

November 8th, 2009 | 3 Comments | Posted in Java, Wicket

While writing some unit tests for a wicket application I was working on, I found that I was writing a lot of component path expressions to get at various components in my pages.
However after some refactoring of the page hierarchy I had to re-write most of the expressions to take make the tests work again.

This lead me to think that maybe there could be an easier way for getting at components, using * to represent any child component at a given level, and ** to represent any child component at any level.

Doing this would mean that you could re-write this:

“panel1:innerpanel1:form1:textfield1”

as

“*:*:form1:textfield1”

or

“**:form:textfield1”

or even

“**:textfield1”

Then I got thinking that I would be pretty simple to place type restrictions on the results, so you could set the following expression:

“**” and type restriction of TextField

to get all TextField component on the page or

“panel1:**” and type restriction of ListView

to get all ListView components which are children of the panel1 component.

To use component expressions I created 4 static methods

  • public static Component findComponent(Component parent,
     String expression)
  • public static Component findComponent(Component parent,
     String expression,Class<? extends Component>typeRestriction)
  • public static List findAllComponents(Component parent,
     String expression)
  • public static List findAllComponents(Component parent,
     String expression, Class<? extends Component> typeRestriction)

The code is checked into the london wicket google code repository, and you can include it as a dependency to your project by adding the following to your pom.xml

<repositories>
	<repository>
		<id>londonwicket</id>
		<url>http://londonwicket.googlecode.com/svn/repo</url>
		<releases>
			<enabled>true</enabled>
		</releases>
		<snapshots>
			<enabled>true</enabled>
		</snapshots>
	</repository>
</repositories>

<dependency>
	<groupId>com.googlecode.londonwicket</groupId>
	<artifactId>wicket-component-expressions</artifactId>
	<version>0.1.0</version>
</dependency>

There are tests to cover all the different cases I could think of. Any comments, bug fixes, or improvements would be more than welcome.

Tags: ,

A ‘LegUp’ for new Java projects

October 7th, 2009 | 9 Comments | Posted in Java

Nowadays, even a simple Java web system is going to require a web framework, some sort of persistence layer and probably some sort of dependency injection.  But how long would it take you to create such a project from scratch?  1 day? 1 hour maybe if you knew all of the technologies involved.  With LegUp you can be up and running in 15 seconds*.

LegUp is a collection of free, open source (Apache 2 licensed) Maven 2 archetypes, and a web based configuration tool provided by jWeekend.  It allows you to choose from different combinations of popular Java technologies (Apache Wicket, Spring, Google Guice, JPA, Hibernate, Warp Persist) to allow you to get up and running quickly and easily.  Up and running means that will have a simple application running within a minute of starting.

Currently the following archetypes are available:

  • Spring 2.5 with a JDBC database layer
  • Spring 2.5 with a JPA 1.0 database layer
  • Apache Wicket 1.4 and Google Guice 1.0
  • Apache Wicket 1.4, Google Guice 1.0, Warp Persist 1.0 and Hibernate 3
  • Apache Wicket 1.4, Google Guice 1.0, Warp Persist 1.0 and JPA 1.0
  • Apache Wicket 1.4, Spring 2.5 and JPA 1.0
The projects using JPA include multiple JPA providers.  Hibernate is the default, but both OpenJPA and EclipseLink are also included.  To change the provider, comment out the hibernate dependency in the projects pom.xml and uncomment the desired provider.  Then comment out/in the appropriate lines in the persistence.xml file.

Example for a project with Wicket, Spring and JPA

  • Make sure you have Java 5+ and Maven 2 installed and working.  You can search on the internet for how to do this if you are not sure.
  • Go to the LegUp configuration page in your web browser of choice.
  • Select the Wicket, Spring, JPA archetype from the drop down list.
  • Optionally customize the Group Id, Archetype Id, Version and Package fields.  These are standard Maven properties.  I will leave the defaults for this example.
  • Click the ‘Generate Maven Command’ button.  This will populate the text area under the button.
  • Open a terminal window (Mac, Linux) or command prompt window (Win) and cd to a suitable directory.
  • Copy the command line (starts with mvn archetype:generate) and paste it into your open terminal.
  • Hit enter and wait for maven to finish processing the command.  The time this will take depends on the speed of your internet connection and how populated your local maven repository is.  It could take a few minutes if this is the first time you have used maven.
  • Cd into the directory which has been produced, this will be named the same as the Archetype Id you entered earlier.  In my case this directory is called ‘myproject’.
    cd myproject
  • Build the application and run the provided tests using this maven command:
    mvn compile test
  • Run the wicket application on jetty with this maven command.
    mvn jetty:run
  • Thats it, you now have a running Wicket Application with Spring Dependency injection and JPA using hibernate under the covers, all running with a HSQL database.

Added bonus feature

If you type the following maven command, it will generate you an eclipse project which you can import into eclipse to start editing the code straight away

mvn eclipse:eclipse

Gotchas

  • Warp Persist will need installing into your local repository manually.  Download it from the Warp Persist website and follow the instructions that maven gives you.
*15 seconds is assuming that your maven repository contains all of the required jars already.
** Disclaimer, I work for jWeekend.
Tags: , , , ,