Advertisment

Java EE Apps with Beehive

author-image
CIOL Bureau
Updated On
New Update

By: Anadi Misra



In this tutorial, we will take you through some sample code

snippets for making aNet-UI and Control based application. We will also look

into their integration with other Java EE based specifications and frameworks

such as JSF.



Creating a Net-UI enabled App

A Net-UI application

has a set of JARs, configuration files and a descriptor, conventionally named as
'web.xml'. Its pre-requisites include 'Apache Ant' and a Java EE App Server/

Servlet Container. Make sure you have Apache Ant's bin directory added to your

system's 'PATH' variable. To start-off you can create a new Net-UI app by

running the following ant command:



ant -f to>\beehive-imports.xml new.netui.webapp

































Direct

Hit!
Applies to: Java

developers
USP: Making JAVA

EE application development easier
Links: href="http://beehive.apache.org">http://beehive.apache.org
Google keywords:

Beehive, net-ui-control



You will be prompted for a 'fully-qualified' path for your

Web app. The Net-UI app directory structure is created with the path you

provided, which contains the 'src' and 'web' directories containing the

configuration and build files. The 'src' directory contains a 'SharedFlow' class

that defines actions, states and exception handlers that will be shared by page

flows that reference this SharedFlow class. The directory structure hence

created is still raw and needs some editing, typically in the build.properties

file in the root directory of the app's folder before we can proceed with

coding:







  • Value for beehive.home entry in the file should point to the

    root directory of Beehive installation.





  • Set a value for 'contextPath' entry. This value is used to

    determine the context-path when the '.war' archive is deployed to an application

    server.





  • If you are not using Apache Tomcat then the entries

    'servlet-api.jar' and 'jsp-api.jar' should also be changed to point to valid

    path values of your system.



Creating the Controller Class

The 'Controller'

class handles page flows along with exceptions-handling and navigation rules in
a Net-UI app. We will implement one that only forwards the page flow

to 'index.jsp' web page.



import

org.apache.beehive.netui.pageflow.annotations.Jpf;

import

org.apache.beehive.netui.pageflow.PageFlowController;
@Jpf.Controller(

simpleActions={

@Jpf.SimpleAction(name="begin",

path="index.jsp")
}

)

public class Controller extends

PageFlowController{}



The '@Jpf.Controller' annotation is a main class-level

annotation whose inclusion is mandatory in a 'Controller' class definition.

Here, we define a simple action using the annotation. Save this file to either

'web' or 'src' directory. When saving in web directory, simply overwrite the
existing 'Controller' class with this one. Next, define a simple JSP page that
displays “Hello World!”. Here's the page definition: size=1>

Advertisment

Hello World!

Hello World from NetUI

Once you've saved all files, run 'ant clean build war' from

your apps root-directory. This will create a deployable '.war' archive with the

name you had specified in the contextPath entry in 'build.properties' file. You

can then deploy your web-archive to your application server following the

procedure applicable on the basis of the web server you have installed. After

deploying the app you can run it by accessing http://localhost:8000/myNet from

your browser. Here 'myNet' is the contextPath we provided in the

'build.properties' file.

Our sample Net UI App

uses the flow that we define in the Controller class to forward the

page flow to an 'index.jsp' page

Creating a Controls App

In our sample Controls app,

we will create a controls interface that contains a 'hello()' method, which will
then be implemented in a different class. Here, first create a directory

structure and then edit 'build.properties' file to ensure a smooth run. Create

an empty directory named 'ctrl-new' in your root drive. Next, we need a

build.xml and a build.properties file. For this we can use the build.xml

provided in the samples/controls-blank folder of the Beehive distribution and

edit it. Copy this file to the 'ctrl-new' directory and change the name field of

project tag to 'Controls Sample'. Next create a 'build.properties' file and add

the path to your Beehive installation's root directory in a 'beehive.home'

variable. A control in Beehive contains an interface that lists all the methods

that can be accessed or invoked by the controls client, i.e. the implementer

class. Our 'Controls Interface' is as follows:



import

org.apache.beehive.controls.api.bean.ControlInterface;

@ControlInterface

public

interface Hello { String hello(); }



The '@ControlInterface' specifies that this is a 'Controls
Interface'. Next implement this simple method in our controls client:



import

org.apache.beehive.controls.api.bean.ControlImplementation;

@ControlImplementation(isTransient=true)

public

class HelloImpl
implements Hello {

public String hello() { return "Hello

World!";
}

}



Save both files in 'src' directory within the 'ctrl-new' root

directory. Next build a sample 'Controls' application using 'ant -f

ctrl-new\build.xml build' command. This will create a 'mycontrols.jar' file in

'build' directory within the root-directory. To use the name of your choice,
edit the property name="build.jar">in build.xml.



Now that we have outlined the basics that govern making

Net-UI or Controls apps, we will look into some advanced features such as

integrating Net-UI with JSF, and extending Controls to create EJBs in the next

part.



Source: PCQuest

tech-news