Develop a Simple Web Application with Apache Wicket and Apache

Develop a Simple Web Application with Apache Wicket and Apache

Develop a simple Web application with Apache Wicket and Apache Geronimo Combine Wicket, Geronimo, and Apache Derby to form an open source Java Web development platform Skill Level: Intermediate Robi Sen ([email protected]) Vice President Department 13 LLC 10 Jul 2007 Apache Wicket is an innovative Java™ Web application framework that was introduced a couple of years ago. It helps simplify Web application development by clearly separating the roles of developers and designers. It lets you remove logical code from the view layer, eliminating the need for JavaServer Pages (JSP), providing a simple plain old Java object (POJO)-centric mode of development, and removing much of the need for XML and other configuration file formats. In this tutorial, learn how to set up your system to develop a simple Web application with Wicket, using Apache Geronimo as your application server and Apache Derby as the embedded database. Section 1. Before you start This tutorial is designed for developers who have found Java frameworks, such as Struts, lacking in needed functionality. If you're interested in developing Web applications in a more object-oriented manner, where the view is clearly separated from logic and there's minimal configuration and mapping, then Wicket is for you! This tutorial walks you through the basics of how Wicket works, while using Apache Geronimo to set up a Java Platform, Enterprise Edition (Java EE) server, Web server, and embedded database in just minutes. Combining Wicket with Geronimo lets you develop data-driven, scalable Web applications using software that's all open source. Develop a simple Web application with Apache Wicket and Apache Geronimo © Copyright IBM Corporation 1994, 2008. All rights reserved. Page 1 of 27 developerWorks® ibm.com/developerWorks About this tutorial Developing Java Web applications can be awkward and frustrating. For years developers have tried to solve problems with Java application development by creating frameworks that solve specific problems. But few have been able to simplify Web development, separate roles, clearly separate the view from the model and remove special markup, and define a totally POJO-centric model of development — until now. Enter Apache Wicket. Wicket, an innovative Java Web application framework introduced a couple of years ago, simplifies Web application development by clearly separating roles of developers and designers, in part by removing logical code from the view layer. This simple and pure approach to Model-View-Controller (MVC) development, coupled with its simple development workflow that lacks XML configuration files, make Wicket a powerful and enjoyable development framework. It solves a number of development challenges, allowing you to focus more on functionality and less on the application configuration. In this tutorial, you zero in on how to set up and configure a project to use the Wicket framework with Databinder, which allows Wicket and Hibernate to work nicely together. You combine these applications with the Apache Derby embedded database to create a simple Web application in record time. From there, you learn how to deploy your application on Geronimo. System requirements You need the following tools to follow along with this tutorial: • Apache Geronimo 2.0-M2 with Tomcat 6 — Geronimo is the Java EE application server that you deploy to. • An operating system — This application was developed using Microsoft® Windows® XP, but everything involved has been widely used on Linux® and OS X. So you should be able to follow the tutorial using platforms other than Windows. • Java JDK 1.5 or later — Java 1.5_11 was used to develop all the code in this tutorial, but 1.5 and later JDKs should work. • Embedded database — This tutorial uses Apache Derby, the lightweight, 100% Java-based database. Because Geronimo already has Derby built in, you don't need to download anything. • Eclipse — In this tutorial, you use Eclipse 3.2 as the IDE. It's not required, but it greatly simplifies your development process. • Apache Maven 2 — You use Maven 2 in this project to automatically gather required files and build projects. Develop a simple Web application with Apache Wicket and Apache Geronimo Page 2 of 27 © Copyright IBM Corporation 1994, 2008. All rights reserved. ibm.com/developerWorks developerWorks® • Databinder — A lightweight utility written by Nathan Hamblen, Databinder is a tool that lets Wicket and Hibernate work together extremely well, greatly simplifying development of data-driven Wicket applications. Section 2. Setting the stage Few Java Web application developers would argue that developing Java Web applications is a straightforward, simple-to-manage, and delightful process. Often Java Web application frameworks, while solving many problems, end up being brittle and difficult to change after their initial development. Furthermore, many frameworks — while espousing separation of concerns and decoupling of logic from presentation — often mix logic and presentation, thus forcing developers to manage overly complex XML files used in configuration and mapping. Wicket solves all of these problems in a novel and elegant way by using only plain HTML on the view layer and POJOs for everything else. Wicket in part solves this problem by extending HTML in a compliant way by introducing the Wicket namespace (wicket:id), which allows Wicket to map specific dynamic functionality to areas of your Web site and associate them with specific models represented by a Java class and subclasses. For most people, the easiest way to learn is by doing, so let's set up an environment and start building your Wicket application. To get started, you need to download Maven 2, which you use to streamline the setup and creation of your Wicket project. You also need to download and set up Geronimo, and finally, if you're not already using it, Eclipse. Download links are available in the System requirements section. Install Java 1.5 Before you do anything, make sure you have Java JDK 1.5 installed on your system and the environment variables PATH pointing to your JDK bin directory. You must also have the Java environment variable JAVA_HOME pointing to your Java install directory. Set up Geronimo For this tutorial, you use Apache Geronimo not only as your Java application server, but also as your database server. Geronimo is a fully compliant Java 2 Platform, Enterprise Edition (J2EE)-certified server that includes an implementation of a servlet container, an Enterprise JavaBeans (EJB) container, a Java Message Service (JMS) provider, a J2EE Connector architecture (JCA) container, and the lightweight Derby database, all licensed under the Apache license. Develop a simple Web application with Apache Wicket and Apache Geronimo © Copyright IBM Corporation 1994, 2008. All rights reserved. Page 3 of 27 developerWorks® ibm.com/developerWorks Setting up Geronimo is simple. To install it: 1. Download it, and unpack it to a directory. For this example, you use C:\geronimo, but you can unpack it anywhere you want. 2. After it's unpacked, there are two ways you can start Geronimo: • Go to the bin directory where you placed Geronimo, which in this case is C:\geronimo\bin, and type java -jar server.jar. • Simply call the startup.bat in the bin directory, or double-click it. The Geronimo server should now start up. 3. After it's started, you can test that everything is working correctly by going to http://localhost:8080/, where you should see something like Figure 1. Figure 1. Successful startup of the Geronimo server Note: The Geronimo server will want to use port 8080 for the server, and Develop a simple Web application with Apache Wicket and Apache Geronimo Page 4 of 27 © Copyright IBM Corporation 1994, 2008. All rights reserved. ibm.com/developerWorks developerWorks® if you know that port is already being used, you'll need to edit the config.xml file, which you can find in C:\geronimo\var\config. For more information about installing Geronimo, refer to the Apache Geronimo wiki (see Resources for a link). Now that you have Geronimo working, it's time to use Maven to set up your environment for working with Wicket. Install and test Maven 2 For this tutorial to help you set up and configure your projects, you're going to use Maven 2 (see System requirements for a link). Maven is a software-management tool that provides a wealth of functionality, from helping manage dependencies to providing project reporting. You need to be connected to the Internet while using Maven. 1. Get the Maven binary (see System requirements for a link), and install the 2.0.7 binary according to the instructions. 2. To test it, open a command prompt, and type mvn -version. You should see something like Maven version: 2.0.7. Now you need to download all the prerequisite JAR files for your project and set up the initial Wicket project. Almost everything you need for this tutorial is automatically downloaded by Maven, except for two JAR files. One is the Sun Java Transaction API (JTA), which, for licensing reasons, can't be held there. 3. For this file, you need to go to the Sun JTA page, select Class Files 1.0.1B, and download it. 4. After it's downloaded, navigate to that download directory, and either type or paste the code shown in Listing 1 into a command shell prompt. Listing 1. Adding Sun JTA to your local Maven repository mvn install:install-file -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar -Dfile=jta-1_0_1B-classes.zip This should add the JTA to your local Maven repository. Now you need to set up and create a Databinder project. Databinder is the toolkit that makes working with Hibernate and Derby from Wicket much easier (see System requirements for a link). 5. To create the Databinder project, type or paste the commands in the command prompt (see Listing 2) in a directory in which you want to create Develop a simple Web application with Apache Wicket and Apache Geronimo © Copyright IBM Corporation 1994, 2008.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    27 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us