Posts Tagged ‘JDeveloper’

Wicket: Full guide for JDeveloper 11g

27 October 2008

This article presents how a complete Wicket project is built from ground-up in JDeveloper 11g.

Go through steps 1-3 to setup a wicket project.

Go through step 4 to create a page.

Go through steps 5-7 to deploy, test and debug the page.

1. Create a web project

File → New… → General → Projects → Web Project → OK.

Creating a new web project in JDeveloper

Creating a new web project in JDeveloper

In the wizard click next, give the project a name, e.g. WicketFun and click Next until the option Finish appears. The project should now appear in the Projects tab.

Project tab of JDeveloper

Project tab of JDeveloper

2. Concentrate all jars

Download wicket from wicket.apache.org → Releases → Wicket 1.4 → Select an appropriate mirror and get apache-wicket-1.4-m3.zip

Download simple logging facade from slf4j.org → Download → slf4j-1.5.2.zip

Create a folder and place inside the following:

  • apache-wicket-1.4-m3\lib\wicket-1.4-m3.jar
  • slf4j-1.5.2\slf4j-simple-1.5.2.jar
  • slf4j-1.5.2\slf4j-api-1.5.2.jar

Add these jars to the classpath by right clicking on the project → Project Properties… → Libraries and Classpath → Add JAR/Directory…

These three are all you need for a wicket application. However, there are some extra interfaces of great interest: The date-time functionality (wicket-datetime-1.4-m2.jar) and the integration with Spring (wicket-spring-1.4-m2.jar).

3. Make the WebApplication

Wicket’s starting point is a WebApplication.

Right click on project → New → General → Simple Files → Java Class → Provide the name MyApplication, declare that it extends WebApplication and click OK.

Create a new class in JDeveloper

Create a new class in JDeveloper

This class should implement the getHomePage() method.

package wicketfun;

import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;

public class MyApplication extends WebApplication {

    public Class<? extends Page> getHomePage() {
        return null;
    }

}

For the time being just let it return null.

Accessing web.xml through the Projects tab

Accessing web.xml through the Projects tab

In the Projects tab double-click on web.xml → XML and paste the following elements

<filter>
   <filter-name>WicketApplication</filter-name>
   <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
   <init-param>
      <param-name>applicationClassName</param-name>
      <param-value>wicketfun.MyApplication</param-value>
   </init-param>
</filter>
<filter-mapping>
   <filter-name>WicketApplication</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

Here’s how web.xml should look.

DD in the XML editor of JDeveloper

DD in the XML editor of JDeveloper

4. Make a page

Let’s call it Hello. We should create Hello.html and Hello.java! As simple as it gets.

Right click on project → New → General → Simple Files → Java Class → Provide the name Hello, the package pages, make it extend WebPage and click OK.

This class should provide a default no-arg constructor.

package pages;

import org.apache.wicket.markup.html.WebPage;

public class Hello extends WebPage {

    public Hello() {
        // wicket action here
    }

}

To make the classes compile right click the project and select Rebuild.

After a successful compilation, right click on project → New… → Web Tier → HTML → HTML Page → Provide the name Hello and click on Browse….

Creating an HTML file in JDeveloper

Creating an HTML file in JDeveloper

Expand the classes folder and double-click on pages.

Bundling the HTML page together with the class file

Bundling the HTML page together with the class file

In this way the html file will be bundled in the same directory with the class file. Just press OK to complete.

Let’s make this page simply display the current year.

<html>
  <body>
      The year is: <span wicket:id="year"></span>
  </body>
</html>

Back to the class for some action.

package pages;

import java.util.Calendar;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;

public class Hello extends WebPage {

    public Hello() {
        Integer year = Calendar.getInstance().get(Calendar.YEAR);
        add(new Label("year", year.toString()));
    }

}

5. Declare the home page

Every time you create a page you’d like to test it.

Just go to the getHomePage() of your WebApplication and make it return your page.

package wicketfun;

import pages.Hello;
import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;

public class MyApplication extends WebApplication {

    public Class<? extends Page> getHomePage() {
        return Hello.class;
    }

}

In this way when the application context is called on the browser, e.g. http://localhost:8080/wicket, this page will be called.

6. Run the page

Deploy the application to your favorite server, for example JBoss, GlassFish or the bundled Weblogic, to see it in action.

7. Debug the page

Wicket keeps the java code totally independent from the HTML markup. So debugging is easy.

Make a breakpoint by clicking on the left of the desired line.

Debugging a wicket page is trivial

Debugging a wicket page is trivial

References

JBoss integration with JDeveloper 11g

26 October 2008

Let’s see how easy is to deploy applications to JBoss by using a handy feature of JDeveloper.

Right click on your project → New → General → Deployment Profiles → WAR File

Creating a WAR file in JDeveloper

Creating a WAR file in JDeveloper

Give a profile name, e.g. wicket, and click OK.

Specifying the name of the deployment profile in JDeveloper

Specifying the name of the deployment profile in JDeveloper

Specify the hot deploy directory of JBoss using the Browse… button.

Configuring the deployment in JDeveloper

Configuring the deployment in JDeveloper

Now you can easily deploy the application by right clicking on project → Deploy → wicket → to WAR file

Easy deployment in JDeveloper

Easy deployment in JDeveloper

Your application is available at http://localhost:8080/wicket/.

Wicket 2: Make a page in JDeveloper

25 August 2008

This is part 2 of a series about Wicket.

JDeveloper provides out-of-the-box support for this excellent framework.

For initial setup information you may recall part 1.

Out-of-the-box

Assume the page Hello that of course IS-A WebPage.

package nikos;

import org.apache.wicket.markup.html.WebPage;

public class Hello extends WebPage {
   public Hello() {
   }
}

To create its HTML file right-click on the project → New… → Web Tier → HTML → HTML Page

In the “Create HTML File” dialog give the name Hello.html, click on “Browse…”

and select the classes/nikos directory.

We’d like a simple page. This is the markup.

<html>
   <body>
      <h1 wicket:id="label"></h1>
   </body>
</html>

Thus we don’t specify any value for the <h1> element. Instead we provide a wicket:id. We’ll use this id to get the element and fill its value through Java!

Let’s return to the class for some action.

package nikos;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;

public class Hello extends WebPage {
   public Hello() {
      add(new Label("label", "Hello from Wicket in JDeveloper!"));
   }
}

Review

  • All the action gets inside this constructor
  • Use JDev’s handy “Create HTML File” dialog to place the html in the same directory as the class file.

GlassFish integration with NetBeans, Eclipse and JDeveloper

9 August 2008

This is how GlassFish integrates with NetBeans 6.1, Eclipse 3.4 (Ganymede) and JDeveloper 11g.

NetBeans

NetBeans 6.1 provides out-of-the box integration as it is bundled with GlassFish.

Just keep the default setting “GlassFish V2 UR2″ enabled during installation process.

In this way GlassFish is automatically installed, configured and ready-to-use: simply press “Run” on any web project!

However, if you would like to declare another installation of GlassFish go to Tools → Servers → Add Server…

Select the proper version, specify the name and click “Next.

Provide the installation path of GlassFish through the “Browse” button and click “Next” to configure the password or “Finish” to complete.

That’s it!

Let’s create a simple web application to test it. Go to File → New Project… → Web → Web Application → Next → Specify the Project Name → Finish

The project should appear on the Projects tab. Edit the code of index.jsp and change <h2>Hello World!</h2> to <h2>Hello World from GlassFish!</h2>

Now simply right-click on the project and select “Run”!

Eclipse

If you are behind a proxy make sure you have properly configured the network settings for HTTPs also. Window → Preferences → General → Network Connections and make sure the option “Use this proxy server for SSL” is checked → Apply → OK → restart Eclipse.

Open the Servers view: Window → Show View → Other… → Server → Servers

On the Servers tab right-click → New → Server

Click on the “Download additional server adapters” link.

Click on the GlassFish Java EE Server option and press “Next”.

Afte reading and accepting the CDDL licence press “Finish” and OK at the prompt message. After a while Eclipse will restart.

Now go the Servers tab right-click → New → Server and select “GlassFish”.

Note: The plugin for brand new GlassFish v3 Technology Preview 2 is already available!

Select the version of GlassFish you have installed and press “Next”.

Provide the installation directory of GlassFish and click “Next”.

That’s it!

JDeveloper

JDeveloper has a really handy feature: deploy-on-demand.

Let’s assume we want to deploy a web application. In the Application Navigator right-click on the project → New… → General → Deployment Profiles

Select war and click “Next”.

After specifying the name, for example “wicket”, provide the hot-deploy directory of GlassFish through the “Browse” button.

That’s it!

To deploy the application simply right-click on the project → Deploy → wicket → to WAR file.