Miles to go …

November 18, 2010

TOTD #150: Collection of GlassFish, NetBeans, JPA, JSF, JAX-WS, EJB, Jersey, MySQL, Rails, Eclipse, and OSGi tips

This is the 150th tip published on this blog so decided to make it a collection of all the previous ones. Here is a tag cloud (created from wordle.net/create) from title of all the tips:

As expected GlassFish is the most prominent topic. And then there are several entries on NetBeans, JRuby/Rails, several Java EE 6 technologies like JPA, JAX-WS, JAX-RS, EJB, and JSF, and more entries on Eclipse, OSGi and some other tecnhologies too. Here is a complete collection of all the tips published so far:

  • #149: How to clean IntelliJ cache, preferences, etc on Mac OS X ?
  • #148: JPA2 Metamodel Classes in NetBeans 7.0 – Writing type-safe Criteria API
  • #147: Java Server Faces 2.0 Composite Components using NetBeans – DRY your code
  • #146: Understanding the EJB 3.1 Timer service in Java EE 6 – Programmatic, Deployment Descriptor, @Schedule
  • #145: CDI Events – a light-weight producer/consumer in Java EE 6
  • #144: CDI @Produces for container-managed @Resource
  • #143: Retrieve Twitter user timeline using using Jersey and OAuth
  • #142: GlassFish 3.1 – SSH Provisioning and Start/Stop instance/cluster on local/remote machines
  • #141: Running GlassFish 3.1 on Ubuntu 10.04 AMI on Amazon EC2
  • #140: Moving GlassFish Installation – Referenced file does not exist "osgi-main.jar"
  • #139: Asynchronous Request Processing using Servlets 3.0 and Java EE 6
  • #138: GlassFish 3.1 Milestone 1 – Clustering and Application Versioning Demos
  • #137: Asynchronous EJB, a light-weight JMS solution – Feature-rich Java EE 6
  • #136: Default Error Page using Servlets 3.0 – Improved productivity using Java EE 6
  • #135: JSF2 Composite Components using NetBeans IDE – lightweight Java EE 6
  • #134: Interceptors 1.1 in Java EE 6 – What and How ?
  • #133: JPA2 (JPQL & Criteria), JavaDB, and embedded GlassFish – perfect recipe for testing
  • #132: Servlets 3.0 in Embedded GlassFish Reloaded – lightweight Java EE 6
  • #131: Dynamic OSGi services in GlassFish – Using ServiceTracker
  • #130: Invoking a OSGi service from a JAX-WS Endpoint – OSGi and Enterprise Java
  • #129: Managed Beans 1.0 in Java EE 6 – What and How ?
  • #128: EJBContainer.createEJBContainer: Embedded EJB using GlassFish v3
  • #127: Embedding GlassFish in an existing OSGi runtime – Eclipse Equinox
  • #126: Creating an OSGi bundles using Eclipse and deploying in GlassFish
  • #125: Creating an OSGi bundles using NetBeans and deploying in GlassFish
  • #124: OSGi Declarative Services in GlassFish – Accessed from a Java EE client
  • #124: Using CDI + JPA with JAX-RS and JAX-WS
  • #123: f:ajax, Bean Validation for JSF, CDI for JSF and JPA 2.0 Criteria API – all in one Java EE 6 sample application
  • #122: Creating a JPA Persistence Unit using NetBeans 6.8
  • #121: JDBC resource for MySQL and Oracle sample database in GlassFish v3
  • #120: Deployment Descriptor-free Java EE 6 application using JSF 2.0 + EJB 3.1 + Servlets 3.0
  • #119: Telnet to GlassFish v3 with NetBeans 6.8 – "Could not open connection to the host"
  • #118: Managing OSGi bundles in GlassFish v3 – asadmin, filesystem, telnet console, web browser, REST, osgish
  • #117: Invoke a JAX-WS Web service from a Rails app deployed in GlassFish
  • #116: GlassFish v3 Administration using JavaFX front-end – JNLP available
  • #115: GlassFish in Eclipse – Integrated Bundle, Install Stand-alone or Update Existing plugin
  • #114: How to enable Java Console in Mac OS X, Windows, … ?
  • #113: JavaFX front-end for GlassFish v3 Administration – Using REST interface
  • #112: Exposing Oracle database tables as RESTful entities using JAX-RS, GlassFish, and NetBeans
  • #111: Rails Scaffold for a pre-existing table using Oracle and GlassFish
  • #110: JRuby on Rails application using Oracle on GlassFish
  • #109: How to convert a JSF managed bean to JSR 299 bean (Web Beans) ?
  • #108: Java EE 6 web application (JSF 2.0 + JPA 2.0 + EJB 3.1) using Oracle, NetBeans, and GlassFish
  • #107: Connect to Oracle database using NetBeans
  • #106: How to install Oracle Database 10g on Mac OS X (Intel) ?
  • TOTD #105: GlassFish v3 Monitoring – How to monitor a Rails app using asadmin, JavaScript, jConsole, REST ?
  • #104: Popular Ruby-on-Rails applications on GlassFish v3 – Redmine, Typo, Substruct
  • #103: GlassFish v3 with different OSGi runtimes – Felix, Equinox, and Knoplerfish
  • #102: Java EE 6 (Servlet 3.0 and EJB 3.1) wizards in Eclipse
  • #101: Applying Servlet 3.0/Java EE 6 “web-fragment.xml” to Lift – Deploy on GlassFish v3
  • #100: Getting Started with Scala Lift on GlassFish v3
  • #99: Creating a Java EE 6 application using MySQL, JPA 2.0 and Servlet 3.0 with GlassFish Tools Bundle for Eclipse
  • #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse
  • #97: GlassFish Plugin with Eclipse 3.5
  • #96: GlassFish v3 REST Interface to Monitoring and Management – JSON, XML, and HTML representations
  • #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application – Getting Started with Java EE 6 using NetBeans 6.8 M1 & GlassFish v3
  • #94: A simple Java Server Faces 2.0 + JPA 2.0 application – Getting Started with Java EE 6 using NetBeans 6.8 M1 & GlassFish v3
  • #93: Getting Started with Java EE 6 using NetBeans 6.8 M1 & GlassFish v3 – A simple Servlet 3.0 + JPA 2.0 app
  • #92: Session Failover for Rails applications running on GlassFish
  • #91: Applying Java EE 6 "web-fragment.xml" to Apache Wicket – Deploy on GlassFish v3
  • #90: Migrating from Wicket 1.3.x to 1.4 – "Couldn’t load DiskPageStore index from file" error
  • #89: How to add pagination to an Apache Wicket application
  • #88: How add pagination to Rails – will_paginate
  • #87: How to fix the error undefined method `new’ for "Rack::Lock":String caused by Warbler/JRuby-Rack ?
  • #86: Getting Started with Apache Wicket on GlassFish
  • #85: Getting Started with Django Applications on GlassFish v3
  • #84: Using Apache + mod_proxy_balancer to load balance Ruby-on-Rails running on GlassFish
  • #83: Eclipse Tools Bundle for GlassFish 1.0 – Now Available!
  • #82: Getting Started with Servlet 3.0 and EJB 3.1 in Java EE 6 using NetBeans 6.7
  • #81: How to use nginx to load balance a cluster of GlassFish Gem ?
  • #80: Sinatra CRUD application using Haml templates with JRuby and GlassFish Gem
  • #79: Getting Started with Sinatra applications on JRuby and GlassFish Gem
  • #78: GlassFish, EclipseLink, and MySQL efficient pagination using LIMIT
  • #77: Running Seam examples with GlassFish
  • #76: JRuby 1.2, Rails 2.3, GlassFish Gem 0.9.3, ActiveRecord JDBC Adapter 0.9.1 – can they work together ?
  • #75: Getting Started with Grails using GlassFish v3 Embedded
  • #74: JRuby and GlassFish Integration Test #5: JRuby 1.2.0 RC2 + Rails 2.x.x + GlassFish + Redmine
  • #73: JRuby and GlassFish Integration Test #4: JRuby 1.2.0 RC2 + Rails 2.2.x + GlassFish v2 + Warbler
  • #72: JRuby and GlassFish Integration Test #3: JRuby 1.2.0 RC2 + Rails 2.2.x + GlassFish v3
  • #71: JRuby and GlassFish Integration Test #2: JRuby 1.2.0 RC1 + Rails 2.2.x + GlassFish v3 Prelude
  • #70: JRuby and GlassFish Integration Test# 1: JRuby 1.2.0 RC1 + Rails 2.2.x + GlassFish Gem
  • #69: GlassFish High Availability/Clustering using Sun Web Server + Load Balancer Plugin on Windows Vista
  • #68: Installing Zones in Open Solaris 2008/11 on Virtual Box
  • #67: How to front-end a GlassFish Cluster with Apache + mod_jk on Mac OSX Leopard ?
  • #66: GlassFish Eclipse Plugin 1.0.16 – Install v3 Prelude from the IDE
  • #65: Windows 7 Beta 1 Build 7000 on Virtual Box: NetBeans + Rails + GlassFish + MySQL
  • #64: OpenSolaris 2008/11 using Virtual Box
  • #63: jmx4r gem – How to manage/monitor your Rails/Merb applications on JRuby/GlassFish ?
  • #62: How to remotely manage/monitor your Rails/Merb applications on JRuby/GlassFish using JMX API ?
  • #61: How to locally manage/monitor your Rails/Merb applications on JRuby/GlassFish using JMX ?
  • #60: Configure MySQL 6.0.x-alpha to NetBeans 6.5
  • #59: How to add Twitter feeds to blogs.sun.com ? + Other Twitter Tools
  • #58: Jersey and GlassFish – how to process POST requests ?
  • #57: Jersey Client API – simple and easy to use
  • #56: Simple RESTful Web service using Jersey and Embeddable GlassFish – Text and JSON output
  • #55: How to build GlassFish v3 Gem ?
  • #54: Java Server Faces with Eclipse IDE
  • #53: Scaffold in Merb using JRuby/GlassFish
  • #52: Getting Started with Merb using GlassFish Gem
  • #51: Embedding Google Maps in Java Server Faces using GMaps4JSF
  • #50: Mojarra 2.0 EDR2 is now available – Try them with GlassFish v3 and NetBeans 6.5
  • #49: Converting a JSF 1.2 application to JSF 2.0 – @ManagedBean
  • #48: Converting a JSF 1.2 application to JSF 2.0 – Facelets and Ajax
  • #47: Getting Started with Mojarra 2.0 nightly on GlassFish v2
  • #46: Facelets with Java Server Faces 1.2
  • #45: Ajaxifying Java Server Faces using JSF Extensions
  • #44: JDBC Connection Pooling for Rails on GlassFish v3
  • #43: GlassFish v3 Build Flavors
  • #42: Hello JavaServer Faces World with NetBeans and GlassFish
  • #41: How I created transparent logo of GlassFish using Gimp ?
  • #40: jQuery Autcomplete widget with MySQL, GlassFish, NetBeans
  • #39: Prototype/Script.aculo.us Autcomplete widget with MySQL, GlassFish, NetBeans
  • #38: Creating a MySQL Persistence Unit using NetBeans IDE
  • #37: SQLite3 with Ruby-on-Rails on GlassFish Gem
  • #36: Writing First Test for a Rails Application
  • #35: Rails Database Connection on Solaris
  • #34: Using Felix Shell with GlassFish
  • #33: Building GlassFish v3 Workspace
  • #32: Rails Deployment on GlassFish v3 from NetBeans IDE
  • #31: CRUD Application using Grails – Hosted on GlassFish and MySQL
  • #30: CRUD Application using Grails – Hosted on Jetty and HSQLDB
  • #29: Enabling "Available Plugins" tab in NetBeans IDE
  • #28: Getting Started with Rails 2.0 Scaffold
  • #27: Configurable Multiple Ruby Platforms in NetBeans 6.1 M1
  • #26: Overriding Database Defaults in Rails 2.0.2
  • #25: Rails application with PostgreSQL database using NetBeans
  • #24: Getting Started with Rails 2.0.x in JRuby 1.0.3 and JRuby 1.1RC1
  • #23: JavaFX Client invoking a Metro endpoint
  • #22: Java SE client for a Metro endpoint
  • #21: Metro 1.1 with GlassFish v2 UR1 and NetBeans 6
  • #20: How to create a new jMaki widget ?
  • #19: How to Add Metro Quality-of-Service to Contract-First Endpoint ?
  • #18: How to Build The GlassFish v3 Gem for JRuby ?
  • #17: Backing Up your Blog Posts on Roller
  • #16: Optimizing Metro Stubs by locally packaging the WSDL
  • #15: Delete/Update Row from Database using jMaki Data Table
  • #14: How to generate JRuby-on-Rails Controller on Windows (#9893)
  • #13: Setup Mongrel for JRuby-on-Rails applications on Windows
  • #12: Invoking a Java EE 5 Web service endpoint from JRuby
  • #11: Setup Mongrel cluster for JRuby-on-Rails applications on Unix
  • #10: Consuming JSON and XML representations generated by a Jersey endpoint in a jMaki Table widget
  • #9: Using JDBC connection pool/JNDI name from GlassFish in Rails Application
  • #8: Generating JSON using JAXB annotations in Jersey
  • #7: Switch between JRuby and CRuby interpreter in NetBeans 6
  • #6: Difference between Ruby Gem and Rails Plugin
  • #5: Loading data from beans in jMaki widgets
  • #4: How to convert a Session EJB to a Web service ?
  • #3: Using JavaDB with JRuby on Rails
  • #2: Change the endpoint address on a pre-generated Web services Stub
  • #1: SOAP Messaging Logging in Metro

Just for fun, here is another tag cloud:

You can access all the tips here. And keep those suggestions coming!

Technorati: totd glassfish netbeans jpa jsf jaxws jersey mysql rails osgi eclipse

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

September 2, 2009

Track your running miles using Apache Wicket, GlassFish, NetBeans, MySQL, and YUI Charts

Filed under: frameworks, glassfish, wicket — Tags: — arungupta @ 2:00 am

Track your running miles using Apache Wicket, GlassFish, NetBeans, MySQL, and YUI Charts

An earlier blog introduced an application that provides basic tracking of your running distance and generate charts to monitor progress.  The idea is to build the same application using different Web frameworks and deploy on GlassFish and then evaluate each framework based upon a pre-defined critieria. The first version was built using JRuby and Ruby-on-Rails. This blog announces the completion of the Apache Wicket version of the application.

All efforts have been applied to ensure a consistent look-and-feel with the original application but there are minor inconsistencies to leverage the default behavior of the framework.

First  here are some snapshots of the application deployed on GlassFish b3 build 61.

The home page looks like:

Here is a summary of all the runlogs:

All the records can be easily paginated through. There are a few validations while adding a new run:

The "datepicker" widget is used for selecting custom dates as shown in the following page:

Here is a line chart of last 30 days of running:

Notice, it also shows the complete summary as well. And finally a barchart for the entire year so far:

The complete instructions to check out and run the Wicket version of this application are available here.

Now comes the time to provide feedback on the Wicket framework based upon my experience of developing this application. The evaluation criteria is explained in detail here.

The feedback may be attributed to my ignorance of the Wicket framework. If so, please feel free to post a comment and I’ll be happy to fix.

  1. MVC separation: Wicket promotes MVC architecture by providing abstract wrappers over model but the actual implementation still needs to be plugged. For example, the controllers need to written from scratch anyway. There is no recommended directory structure that makes MVC inherent. This is related to the fact that Wicket is not a full-stack framework (more on this below).

    The framework provides a clean separation between views in HTML/CSS and business logic using POJO. However a lot (quite a lot) of glue code needs to be written to stitch them together. And it gets verbose really fast because of the multiple inner classes that keeps popping everywhere in the Java code. Also by default POJO and HTML are packaged together and mixing views/models in the same directory is very confusing.

  2. DRY and CoC principles: The framework neither explicitly promote or prohibit DRY or CoC. The standard HTML/CSS/Java techniques can be used to achieve DRY. And because there is no generated code, there is no concept of CoC.
  3. Limited Ajax: The framework provides buttons/links that can make an Ajax request to the back end. But there is no explicit abstraction of XmlHTTPRequest in the framework. And so an external JavaScript library needs to pulled (Prototype in this case) for any direct Ajax invocations.

    The documentation on wicketstuff-prototype is kinda unclear on how the integration works.

  4. ORM: Apache Wicket is a framework for creating UI applications and that’s exactly what it is, nothing beyond. It is not comparable with full stack frameworks like Java EE, Rails or Grails which provides a persistence mechanism, database connectivity, full MVC support, security and other similar features. As a result, this application could not be built using only Wicket. For example, Java Persistence API (JPA) was used for database access and Prototype was used for Ajax functionality. JPA and Prototype are just the chosen ones among other multiple options available.

    1. CRUD generation: Creating a basic CRUD applications required putting together a bunch of POJOs, corresponding HTML pages, JPA controllers and stitching them together.
    2. Table creation: Defined by the chosen persistence library.
    3. Loading data in the table: Defined by the chosen persistence library.
    4. Customizing queries: Defined by the chosen persistence library.
  5. Customization

    1. CSS & JavaScript: Standard HTML, CSS, and JavaScript techniques for packaging are used.
    2. Form Validation & Default Error Handling: There are validators available to enable basic checking like required, number / pattern / range / date validator. Anything above that needs to be custom built and adds to the verbose nature of the framework. For example a "FormValidator" was built to support the validation for each elements of the form. Custom messages for each validation message can be displayed as explained here. More user-friendly messages can be displayed as explained here.
    3. Templates: The template mechanism is really flexible and allows the repetitive code to be easily captured using "markup inheritance".
  6. 3rd Party Libraries: Adding 3rd-party libraries is quite a breeze because standard HTML/CSS/JavaScript integration techniques are used.

    1. Plugins: Wicket-extensions has some components in addition to the core framework. Wicket-stuff provides components that complement the core framework. The core functionality can be extended using wicket-stuff.
    2. Date picker: There are corresponding packages available for YUI, e.g. "org.apache.wicket.extensions.yui.calendar" for adding DatePicker widget.
    3. Pagination was quite simple to implement.
  7. IDEs: NetBeans provides the most advanced support for Wicket development. But the recommended way is to start with a Maven project and NetBeans provide good support for that as well. More on IDE support here. The Edit/Save/Deploy/Refresh cycle required by the Jetty is time consuming though.
  8. Browser Compatibility: The app was tested on Firefox 3.5.2 (on Mac), Safari 4.0.3 (on Mac) and IE 7.0.600.118000 (on Windows Vista) and no issues were encountered.
  9. Production Deployment: Generating a production deployment on GlassFish is very straight forward because of Maven, just create a WAR file using "mvn package" and deploy directly.
  10. Maintainability: The framework requires a good grasp of Object Oriented concepts like inheritance, encapsulation and inner classes. Even though these concepts are very powerful but they can be a maintenance nightmare. Also, the verbose nature of framework will likely make it cumbersome as a maintenance effort. However there is no real experience or feedback in this area.
  11. Any outstanding feature ? – The response time on the Wicket user list is truly outstanding. Most of my issues encountered during the development phase were resolved by asking questions there.
  12. Any pain point ? – As with any new framework, there is always a learning curve. The framework has a large set of APIs and so it takes a while to figure how the pieces fit together and can be assembled together to create a solution. If you are developing with Wicket, then the official documentation is pretty minimal and not much helpful. The very first link in the documentation actually points to Books on Wicket which is indeed a key resource. I borrowed "Wicket in Action" book from a colleague and it turned out to be helpful. But unfortunately the API has evolved since the book was released and so some of the recommendations from the book are already deprecated. The Wicket user list is definitely a very responsive resource and help me build a better understanding of the framework. Wicket Stuff provides a good set of examples as well with complete source code. But even here some of the samples are using deprecated APIs. Another pain point is that "search engine-driven development" paradigm cannot be applied easily because the search results are a mix from the pre- and post-Apache versions of blogs/docs/etc.

The latest version of this evaluation is available here.

TOTD #86 explains how to get started with using Apache Wicket and GlassFish. All other Wicket related entries on this blog are here.

Technorati: wicket glassfish netbeans mysql yahoo yui chart running miles framework

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

August 11, 2009

TOTD #91: Applying Java EE 6 “web-fragment.xml” to Apache Wicket – Deploy on GlassFish v3

Filed under: glassfish, javaee, totd, wicket — Tags: , , , — arungupta @ 4:00 am

“Extensibility” is a major theme of Java EE 6. This theme enables seamless pluggability of other popular Web frameworks with Java EE 6.

Before Java EE 6, these frameworks have to rely upon registering servlet listeners/filters in “web.xml” or some other similar mechanism to register the framework with the Web container. Thus your application and framework deployment descriptors are mixed together. As an application developer you need to figure out the magical descriptors of the framework that will make this registration.

What if you are using multiple frameworks ? Then “web.xml” need to have multiple of those listeners/servlets. So your deployment descriptor becomes daunting and maintenance nightmare even before any application deployment artifacts are added.

Instead you should focus on your application descriptors and let the framework developer provide the descriptors along with their jar file so that the registration is indeed magical.

For that, the Servlet 3.0 specification introduces “web module deployment descriptor fragment” (aka “web-fragment.xml”). The spec defines it as:

A web fragment is a logical partitioning of the web app in such a way that the frameworks being used within the web app can define all the artifacts without asking devlopers to edit or add information in the web.xml.

Basically, the framework configuration deployment descriptor can now be defined in “META-INF/web-fragment.xml” in the JAR file of the framework. The Web container picks up and use the configuration for registering the framework. The spec clearly defines the rules around ordering, duplicates and other complexities.

TOTD #86 explained how to get started with Apache Wicket on GlassFish. This Tip Of The Day (TOTD) explains how to leverage ”web-fragment.xml” to deploy a Wicket application on GlassFish v3. The basic concepts are also discussed here.

For the “Hello World” app discussed in TOTD #86, the generated “web.xml” looks like:

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<web-app xmlns=”http://java.sun.com/xml/ns/j2ee”
         xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
         xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”
         version=”2.4″>

        <display-name>helloworld</display-name>

         <!– 
              There are three means to configure Wickets configuration mode and they are
              tested in the order given.
              1) A system property: -Dwicket.configuration
              2) servlet specific <init-param>
              3) context specific <context-param>
              The value might be either “development” (reloading when templates change)
              or “deployment”. If no configuration is found, “development” is the default.
        –>

        <filter>
                <filter-name>wicket.helloworld</filter-name>
                <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
                <init-param>
                        <param-name>applicationClassName</param-name>
                        <param-value>org.glassfish.samples.WicketApplication</param-value>
                </init-param>
        </filter>

 <filter-mapping>
  <filter-name>wicket.helloworld</filter-name>
        <url-pattern>/*</url-pattern>
 </filter-mapping>

</web-app>

This deployment descriptor defines a Servlet Filter (wicket.helloworld) that registers the Wicket framework with the Web container. The filter specifies an initialization parameter that specifies the class name of the Wicket application to be loaded. And it also contains some other information that is also relevant to the framework. None of this application is either required or specified by the application. And so that makes this fragment a suitable candidate for “web-fragment.xml”.

Here are the simple steps to make this change:

  1. Remove “src/main/webapp/WEB-INF/web.xml” because no application specific deployment descriptors are required.
  2. Include “wicket-quickstart-web-fragment.jar” in the “WEB-INF/lib” directory of your application by adding the following fragment in your “pom.xml”:
        <dependencies>

            . . .
            <!– web-fragment –>
            <dependency>
                <groupId>org.glassfish.extras</groupId>
                <artifactId>wicket-quickstart-web-fragment</artifactId>
                <version>1.0</version>
                <scope>runtime</scope>
            </dependency>
        </dependencies>

       . . .

        <repositories>
            <repository>
                <id>maven2-repository.dev.java.net</id>
                <name>Java.net Repository for Maven</name>
             &nbsp
    ;  <url>http://download.java.net/maven/2/</url>
            </repository>
        </repositories>

    This file contains only “META-INF/web-fragment.xml” with the following content:

    <web-fragment>
            <filter>
                    <filter-name>wicket.helloworld</filter-name>
                    <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
                    <init-param>
                            <param-name>applicationClassName</param-name>
                            <param-value>org.glassfish.samples.WicketApplication</param-value>
                    </init-param>
            </filter>

            <filter-mapping>
                    <filter-name>wicket.helloworld</filter-name>
                    <url-pattern>/*</url-pattern>
            </filter-mapping>
    </web-fragment>

  3. Create the WAR file without “web.xml” by editing “pom.xml” and adding the following fragment:
          <plugins>
                . . .
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.1-beta-1</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
                . . .
          </plugins>

That’s it, now you can create a WAR file using “mvn package” and deploy this web application on GlassFish v3 latest promoted build (58 as of today) as explained in TOTD #86.

The updated WAR file structure looks like:

helloworld-1.0-SNAPSHOT
helloworld-1.0-SNAPSHOT/META-INF
helloworld-1.0-SNAPSHOT/WEB-INF
helloworld-1.0-SNAPSHOT/WEB-INF/classes
helloworld-1.0-SNAPSHOT/WEB-INF/classes/log4j.properties
helloworld-1.0-SNAPSHOT/WEB-INF/classes/org
helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish
helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish/samples
helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish/samples/HomePage.class
helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish/samples/HomePage.html
helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish/samples/WicketApplication.class
helloworld-1.0-SNAPSHOT/WEB-INF/lib
helloworld-1.0-SNAPSHOT/WEB-INF/lib/log4j-1.2.14.jar
helloworld-1.0-SNAPSHOT/WEB-INF/lib/slf4j-api-1.4.2.jar
helloworld-1.0-SNAPSHOT/WEB-INF/lib/slf4j-log4j12-1.4.2.jar
helloworld-1.0-SNAPSHOT/WEB-INF/lib/wicket-1.4.0.jar
helloworld-1.0-SNAPSHOT/WEB-INF/lib/wicket-quickstart-web-fragment-1.0.jar

Notice, there is no “web.xml” and the additional “wicket-quickstart-web-fragment-1.0.jar” and everything works as is!

It would be nice if the next version of wicket-*.jar can include “META-INF/web-fragment.xml” then everything will work out-of-the-box :)

Here is a snapshot of the deployed application:

Are you deploying your Wicket applications on GlassFish ?

Technorati: totd glassfish v3 wicket javaee6 servlet web-fragment

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

August 6, 2009

TOTD #90: Migrating from Wicket 1.3.x to 1.4 – “Couldn’t load DiskPageStore index from file” error

Filed under: totd, wicket — arungupta @ 3:00 am

Now that Apache Wicket 1.4 is available, migrating from previous versions is pretty straight forward.

Change the version in your POM file as:

<wicket.version>1.4.0</wicket.version>

And that’s it!

The complete dependency may look like:

<dependency>
  <groupId>org.apache.wicket</groupId>
  <artifactId>wicket</artifactId>
  <version>1.4.0</version>
</dependency>

or

<dependency>
  <groupId>org.apache.wicket</groupId>
  <artifactId>wicket</artifactId>
  <version>${wicket.version}</version>
</dependency>

You may encounter the following error:

2009-08-05 05:58:49.387::INFO:  No Transaction manager found – if your webapp requires one, please configure one.
ERROR – DiskPageStore              – Couldn’t load DiskPageStore index from file /Users/arungupta/workspaces/runner~subversion/wicket/runner/target/work/wicket.runner-filestore/DiskPageStoreIndex.
java.lang.ClassNotFoundException: org.apache.wicket.util.concurrent.ConcurrentHashMap
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:319)

At least I did :)

Fortunately the fix is simple and intuitive. Instead of running “mvn jetty:run”, invoke the command:

mvn clean jetty:run

Basically, “clean” will clean out references to older version of Wicket jars in your project and voila!

If you are deploying as WAR file, then bundle Wicket jars in WEB-INF/lib instead of copying them to the shared folder of your application server.

Other Wicket tips on this blog are available here. Specifically TOTD #86 shows how to get started with Apache Wicket on GlassFish.

Please leave suggestions on other TOTD (Tip Of The Day) that you’d like to see. A complete archive of all the tips is available here.

Technorati: wicket glassfish migration

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

August 5, 2009

TOTD #89: How to add pagination to an Apache Wicket application

Filed under: totd, wicket — arungupta @ 1:00 am

TOTD #86 explained how to get started with deploying a Apache Wicket application on GlassFish. This Tip Of The Day (TOTD) will show how to add pagination to your Wicket application.

The blog entry “JPA/Hibernate and Wicket Repeating Views with Netbeans” Part 1 and 2 explain in detail how to create a CRUD application using NetBeans, JPA, Hibernate and Wicket. This blog uses the data created in TOTD #38 for the database table.

  1. After creating the JPA Controller, adding the IDataProvider and DataView implementations and hooking together, the application is available at “http://localhost:8080/helloworld” and looks like:

    As noticed in the output, all the states are listed in one page. The HTML markup looks like:

    <html>
        <head>
            <title>Wicket Quickstart Archetype Homepage</title>
        </head>
        <body>
            <strong>Wicket Quickstart Archetype Homepage</strong>
            <br/><br/>
            <span wicket:id=”message”>message will be here</span>
            <table>
                <tr>
                    <th>ID</th>
                    <th>Abbreviation</th>
                    <th>Name</th>
                </tr>
                <tr wicket:id=”rows”>
                    <td><span wicket:id=”id”>ID</span></td>
                    <td><span wicket:id=”abbrev”>Abbreviation</span></td>
                    <td><span wicket:id=”name”>Name</span></td>
                </tr>
            </table>

        </body>
    </html>

    The backing POJO looks like:

    package org.glassfish.samples;

    import java.util.Iterator;
    import org.apache.wicket.PageParameters;
    import org.apache.wicket.markup.html.basic.Label;
    import org.apache.wicket.markup.html.WebPage;
    import org.apache.wicket.markup.repeater.Item;
    import org.apache.wicket.markup.repeater.data.DataView;
    import org.apache.wicket.markup.repeater.data.IDataProvider;
    import org.apache.wicket.model.CompoundPropertyModel;
    import org.apache.wicket.model.IModel;
    import org.apache.wicket.model.LoadableDetachableModel;
    import org.glassfish.samples.controller.StatesJpaController;
    import org.glassfish.samples.model.States;

    /**
     * Homepage
     */
    public class HomePage extends WebPage {

        private static final long serialVersionUID = 1L;

        // TODO Add any page properties or variables here

        /**
         * Constructor that is invoked when page is invoked without a session.
         *
         * @param parameters
         *            Page parameters
         */
        public HomePage(final PageParameters parameters) {

            // Add the simplest type of label
            add(new Label(“message”, “If you see this message wicket is properly configured and running”));

            // TODO Add your page’s components here

                    // create a Data Provider
            IDataProvider statesProvider = new IDataProvider() {
                public Iterator iterator(int first, int count) {
                    StatesJpaController sc = new StatesJpaController();
                    return sc.findStatesEntities(count, first).iterator();
                }

                public int size() {
                    StatesJpaController sc = new StatesJpaController();
                    return sc.getStatesCount();
                }

                public IModel model(final Object object) {
                    return new LoadableDetachableModel() {
                        @Override
                        protected States load() {
                            return (States)object;
                        }
                    };
                }

                public void detach() {
                }
            };

            // TODO Add your page’s components here

        &nbsp
    ;   DataView dataView = new DataView(“rows”, statesProvider) {

                @Override
                protected void populateItem(Item item) {
                    States state = (States)item.getModelObject();
                    item.setModel(new CompoundPropertyModel(state));
                    item.add(new Label(“id”));
                    item.add(new Label(“abbrev”));
                    item.add(new Label(“name”));
                }
            };

            add(dataView);
        }
    }

    and “persistence.xml” looks like:

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <persistence version=”1.0″ xmlns=”http://java.sun.com/xml/ns/persistence” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd”>
      <persistence-unit name=”helloworld” transaction-type=”RESOURCE_LOCAL”>
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>org.glassfish.samples.model.States</class>
        <properties>
          <property name=”hibernate.connection.username” value=”app”/>
          <property name=”hibernate.connection.driver_class” value=”org.apache.derby.jdbc.ClientDriver”/>
          <property name=”hibernate.connection.password” value=”app”/>
          <property name=”hibernate.connection.url” value=”jdbc:derby://localhost:1527/sample”/>
        </properties>
      </persistence-unit>
    </persistence>
  2. Lets add pagination to this simple sample.
    1. In the POJO, change DataView constructor so that it looks like:

              DataView dataView = new DataView(“rows”, statesProvider, 5)

      where “5″ is the number of entries displayed per page. Alternatively you can also set the number of items per page by invoking:

      dataView.setItemsPerPage(5);

    2. In the HTML page, add the following right after “<table/>”:
      <span wicket:id=”pager”>message will be here</span><br>

      as the last line. This is the placeholder for pagination controls.

    3. In the POJO, add the following:
              PagingNavigator pager = new PagingNavigator(“pager”, dataView);
              add(pager);

      right after “add(dateView);”.

      The output now looks like:

      and clicking on “>” shows:

      And finally clicking on “>>” shows

      The information is now nicely split amongst multiple pages.

So just adding a pagination controls placeholder in the HTML and a corresponding configuration in DataView (in the backing POJO) did the trick for us.

Please leave suggestions on other TOTD (Tip Of The Day) that you’d like to see. A complete archive of all the tips is available here.

Technorati: wicket glassfish pagination

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

July 29, 2009

TOTD# 86: Getting Started with Apache Wicket on GlassFish

Filed under: totd, wicket — arungupta @ 11:00 pm


Apache Wicket is an application framework to build web applications using HTML for markup and POJOs to capture the business logic and all other processing. Why Wicket digs more into the motivation behind this framework.

This Tip Of The Day (TOTD) shows how to create a simple Wicket application and get it running on GlassFish:

  1. Create a Wicket project as:

    ~/samples/wicket >mvn archetype:create -DarchetypeGroupId=org.apache.wicket -DarchetypeArtifactId=wicket-archetype-quickstart -DarchetypeVersion=1.3.6 -DgroupId=org.glassfish.samples -DartifactId=helloworld
    [INFO] Scanning for projects…
    [INFO] Searching repository for plugin with prefix: ‘archetype’.
    [INFO] ————————————————————————
    [INFO] Building Maven Default Project
    [INFO]    task-segment: [archetype:create] (aggregator-style)
    [INFO] ————————————————————————
    [INFO] Setting property: classpath.resource.loader.class => ‘org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader’.
    [INFO] Setting property: velocimacro.messages.on => ‘false’.
    [INFO] Setting property: resource.loader => ‘classpath’.
    [INFO] Setting property: resource.manager.logwhenfound => ‘false’.
    [INFO] [archetype:create]
    [WARNING] This goal is deprecated. Please use mvn archetype:generate instead
    [INFO] Defaulting package to group ID: org.glassfish.samples
    [INFO] —————————————————————————-
    [INFO] Using following parameters for creating OldArchetype: wicket-archetype-quickstart:1.3.6
    [INFO] —————————————————————————-
    [INFO] Parameter: groupId, Value: org.glassfish.samples
    [INFO] Parameter: packageName, Value: org.glassfish.samples
    [INFO] Parameter: package, Value: org.glassfish.samples
    [INFO] Parameter: artifactId, Value: helloworld
    [INFO] Parameter: basedir, Value: /Users/arungupta/samples/wicket
    [INFO] Parameter: version, Value: 1.0-SNAPSHOT
    [INFO] ********************* End of debug info from resources from generated POM ***********************
    [INFO] OldArchetype created in dir: /Users/arungupta/samples/wicket/helloworld
    [INFO] ————————————————————————
    [INFO] BUILD SUCCESSFUL
    [INFO] ————————————————————————
    [INFO] Total time: 3 seconds
    [INFO] Finished at: Tue Jul 28 15:30:21 PDT 2009
    [INFO] Final Memory: 12M/80M
    [INFO] ————————————————————————
  2. Run it using the pre-configured Jetty plugin as:
    ~/samples/wicket/helloworld >mvn jetty:run
    [INFO] Scanning for projects…
    [INFO] Searching repository for plugin with prefix: ‘jetty’.
    [INFO] ————————————————————————
    [INFO] Building quickstart
    [INFO]    task-segment: [jetty:run]
    [INFO] ————————————————————————
    [INFO] Preparing jetty:run
    [INFO] [resources:resources]
    [INFO] Using default encoding to copy filtered resources.
    [INFO] [compiler:compile]
    [INFO] Compiling 2 source files to /Users/arungupta/samples/wicket/helloworld/target/classes
    [INFO] [resources:testResources]
    [INFO] Using default encoding to copy filtered resources.
    [INFO] [compiler:testCompile]
    [INFO] Compiling 2 source files to /Users/arungupta/samples/wicket/helloworld/target/test-classes
    [INFO] [jetty:run]
    [INFO] Configuring Jetty for project: quickstart
    [INFO] Webapp source directory = /Users/arungupta/samples/wicket/helloworld/src/main/webapp
    [INFO] Reload Mechanic: automatic
    [INFO] Classes = /Users/arungupta/samples/wicket/helloworld/target/classes
    2009-07-28 15:31:35.820::INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
    [INFO] Context path = /helloworld
    [INFO] Tmp directory =  determined at runtime
    [INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
    [INFO] Web overrides =  none

    . . .

    INFO  – WebApplication             – [WicketApplication] Started Wicket version 1.3.6 in development mode
    ********************************************************************
    *** WARNING: Wicket is running in DEVELOPMENT mode.              ***
    ***                               ^^^^^^^^^^^                    ***
    *** Do NOT deploy to your live server(s) without changing this.  ***
    *** See Application#getConfigurationType() for more information. ***
    ********************************************************************
    2009-07-28 15:31:37.333::INFO:  Started [email protected]:8080
    [INFO] Started Jetty Server

    And the default web page is available at “http://localhost:8080/helloworld” and looks like:

    A later blog will show how to run this application using Embedded GlassFish. But for now lets package the application as a WAR file and deploy it on GlassFish.

  3. Download GlassFish v3 Preview and unzip.
  4. Create a WAR file as:
    ~/samples/wicket/helloworld >mvn package
    [INFO] Scanning for projects…
    [INFO] ————————————————————————
    [INFO] Building quickstart
    [INFO]    task-segment: [package]

    . . .

    [INFO] Processing war project
    [INFO] Webapp assembled in[494 msecs]
    [INFO] Building war: /Users/arungupta/samples/wicket/helloworld/target/helloworld-1.0-SNAPSHOT.war
    [INFO] ————————————————————————
    [INFO] BUILD SUCCESSFUL
    [INFO] ————————————————————————
    [INFO] Total time: 6 seconds
    [INFO] Finished at: Tue Jul 28 15:35:59 PDT 2009
    [INFO] Final Memory: 14M/80M
    [INFO] ——————————–
    —————————————-

    and deploy as:

    ~/samples/wicket/helloworld >~/tools/glassfish/v3/preview/glassfishv3/bin/asadmin deploy target/helloworld-1.0-SNAPSHOT.war

    Command deploy executed successfully.

    The app is now accessible at “http://localhost:8080/helloworld-1.0-SNAPSHOT” and looks like:

Cool, that was pretty straight forward!

Now that’s a very vanilla application but at least shows that Wicket applications can be deployed on GlassFish out-of-the-box. A slightly more complex application will be shared on this blog in future.

Here are some more useful links for Wicket:

  • Wicket Quickstart shows how to create a Wicket application and get started easily.
  • Wicket Examples provide a flavor of how the code is structured.
  • Wicket in Action is a great book that explains the concepts very well.
  • May want to look at wicket-extensions for a list of gadgets/widgets that extend the core capability of the framework.

A few related blog posts planned:

  • Run Wicket application using Embedded GlassFish
  • Use Servlet 3.0 web-fragments.xml and leverage GlassFish v3 Pluggability to run Wicket applications
  • A Wicket version of Track your running miles application
  • Deploying Wicket applications from NetBeans to GlassFish

In the meanwhile, let us know if you are deploying your Wicket applications on GlassFish.

Please leave suggestions on other TOTD that you’d like to see. A complete archive of all the tips is available here.

Technorati: totd wicket glassfish netbeans

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress