by July 16, 2006 0 comments



In the previous articles we talked about developing applications with Net-UI,
the lightweight web front-end framework in Beehive. We also demonstrated the
sample Controls ‘.jar’ archive. This time, we will take you through a few
more advanced features of the Beehive framework. The Net-UI applications can
also be integrated with JSF (Java Server Faces). You need the JSF reference
implementation 1.1 installed on your system for that. You can also use MyFaces
1.0.9 or later versions. While the Net-UI provides a lightweight and compact
option for Web applications, it fails to do much when it comes to managing the
sea of configuration files. In case of such integration you will have to deal
with at least three ‘config’ files to get things sorted as far as servlets
registry, mappings and filter mappings are concerned. We will take you through
the code snippets and tweaks required to integrate these two frameworks. We will
also code Controls extensions for both Session and Entity EJBs. These extensions
allow a direct access to beans for your Web services or applications.

Direct
Hit!
Applies
to:
Java developers
USP:
Integrate Net-UI with Faces implementations
Links:
http://beehive.apache.org 
Google
keywords:
Beehive

Getting started
Create a blank Net-UI application as we described in the earlier parts of the
series. For integrating with JSF, you need to make some additional changes to
‘build.properties’ other than the ones done in a simple Net-UI application.
If you are using the JSF reference implementation, you need to add the following
in this file:

jsf-ri.dir=

In case of MyFaces, it changes to ‘myfaces.dir=‘.

You need to configure ‘faces-config.xml’ also in this case. But first
make some changes to the web.xml file. Remember, what you have to do depends on
the implementation being used. You can enable validation for both the XML syntax
in ‘face-config.xml’ and application objects such as converters, validators
and renderers. Add the following code to the web.xml file to enable these
features:

com.sun.faces.validateXML true
com.sun.faces.verifyObjects true

The default value for these parameters is ‘false’. Additionally you need
to register the Faces servlet and configure its mapping. In case of MyFaces you
don’t need these context parameters, but just register the servlets and
configure their mapping.


Faces Servlet
javax.faces.webapp.FacesServlet
1

The servlet mapping will be as follows.


Faces Servlet
*.faces

The Faces configuration file
A Faces configuration for an application integrating Net-UI to JSF needs a ‘
element, which describes factory for page flow. This is as follows.



org.apache.beehive.Net-UI.pageflow.faces.PageFlowApplicationFactory

This element will come below the ‘‘ element and
before the element, if the latter is used.

JSF integration snippet
Once you take care of the configuration parameters for the integration, the rest
is pretty straightforward. Net-UI enables direct integration with JSF
implementations in many ways; for example it allows components in JSF pages to
raise page-flow actions directly. A page flow directed to a JSF page that
resides in the jsf/pages subdirectory needs the following code snippet in
Controller class:

@Jpf.Controller {
@Jpf.SimpleAction{name=”jsfStart” path=”/jsf/pages/startPage.faces”}
}

The JSF page can then take over the flow through the built-in ‘action’
attribute and even bind data values to objects. The syntax for the binding takes
the following form where the agent is the ‘pageInput’ data with a property
‘agentAreaCode’.

#{pageInput.agent.agentAreaCode}

EJB Controls
Like the Net-UI framework, Controls too can be extended to EJBs. However, it
doesn’t create an EJB alternative but simplifies
access to an EJB resource. In Beehive terms, EJB Controls allow you to write
code for a Web service or a Web page to access a bean’s business methods
directly. The EJB Control manages the tasks of JNDI lookup, interface registry
and instance creation. Let us look at some annotations that Controls offer for
the mechanisms we described earlier. The EJB entity-bean control extension is as
follows.

import org.apache.beehive.controls.api.bean.ControlExtension;
import org.apache.beehive.controls.system.ejb.EntityEJBControl;
import org.apache.beehive.controls.system.ejb.EJBControl.EJBHome;
import org.apache.beehive.pcq.EntityHome;
import org.apache.beehive.pcq.EntityRemote;
@ControlExtension
@EJBHome(jndiName=”org.apache.beehive.pcq.EntityHome”)
public interface PCQEJBControl
extends EntityEJBControl, EntityHome, EntityRemote {
}

The ‘@ControlExtension’ above tells the processor that this is a Controls
extension to EJB. The ‘@EJBHome’ annotation describes the target EJB home
interface using the ‘jndiName’ attribute. Alternately you can use the ‘ejbLink’
attribute. In the latter case, you have to provide an application relative path
to EJB Jar file. In our case, using the ‘ejbLink’ attribute would change the
syntax to

@EJBHome(ejbLink=”helloEJB.jar#HelloWorldBean”)

Additionally for a Session EJB control extension, Controls has an ‘@JNDIContextEnv’
annotation that is optional to use and simplifies the JNDI look-up procedures.
Its attributes carry all the information for JNDI resource lookup.

Conclusion
We outlined the basics and code snippets for enabling Net-UI in a Web
application presentation tier. And in case it’s only Net-UI based Web pages in
your presentation tier, the ant command scripts ease your tasks further by
providing a skeletal structure with ready to use framework and the
pre-configured descriptors. Also when you do integration, you have to manage
only the descriptors, while the page flow is managed as it is for only Net-UI
pages. However, there are frameworks that would even allow you to write Web
applications with much lesser configuration hassles.
Coming to Controls, you can use it as an option for connecting Web-services or
pages to underlying EJB implementations. These solutions have harnessed the
generics and annotations to provide alternatives for proprietary procedures. The
extent of their adoption will, however, be guided more by how easier it is to
incorporate Beehive-based architectures in comparison to other frameworks.
Net-UI certainly has to improve for that.

Anadi Misra

No Comments so far

Jump into a conversation

No Comments Yet!

You can be the one to start a conversation.

<