Sunday, July 03, 2011

Creating a Maven Web Application Archetype in NetBeans 7.0

Slide | The Seven Rules of Great Web Applicati...Image by quasarkitten via Flickr
The  basics for creating a Maven archetype can be found in the Maven - Guide to Creating Archetypes. The guide gives general guidelines for creating an archetype, but no specific details for web applications. This tutorial will show you a simple way of creating a web application archetype and using it. We will use NetBeans 7.0 to create our project, create the archetype, and consume it. This application uses JSF 2.x and GlassFish. However the principles are the same for web applications in general.

The first more practical approach is to create, or use an existing application, and convert it to an archetype.
  1. Create a new Maven web project in NetBeans.
  2. Modify the pom.xml to include the dependencies you require in the project.
  3. (Optional) Modify the pom.xml to include a license
  4. (Optional) Create a web.xml. This is not required for JEE6 web application generally. However, we need one for the Faces Servlet.
  5. (Optional) Add a resource file for externalizing message resources
  6. Create a basic web page, and supporting classes. JSF for example has the following.
    • Index.xhtml
    • IndexBean.java is a Java EE 6 JSF @ManagedBean, and @RequestScoped bean. You could use @Named and @RequstScoped from CDI as well.
  7. Once you are satisfied withe the project, execute mvn archetype:create-from-project. This will create your new archetype in the target/generated-sources/ directory.
  8. Open the newly created project in NetBeans and make any necessary changes.
  9. Next execute mvn install. This will install your new archetype in the local repository.
  10. Create a new project using the new archetype, and run it.
Here is a link to the project: jsf2.zip You can create the archetype from it.

I have created a Youtube video that demonstrates the process.




Enhanced by Zemanta

Friday, July 01, 2011

JSF 2.x and jQuery onload Control

I was asked if there was a way to control Mojarra JSF 2.x components with jQuery. In this case they wanted to be able to control some aspect of the controls from JavaScript on the loading of the document. Here are a couple of quick examples of controlling JSF components using jQuery.
  • Set the background to a light gray
  • Disable form1:inputText1
  • Change the value of form1:inputText2 to Hello World! using a EL assignment to a JavaScript variable.
  • Set form1:inputText3 to be required.

index.xhtml




IndexBean.java


//  Copyright 2011 Blue Lotus Software, LLC.
//  Copyright 2011 John Yeary.
package bean;

import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;

/**
 *
 * @author John Yeary
 * @version 1.0
 */
@ManagedBean
@RequestScoped
public class IndexBean {

    private String value = "Hello World";

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}



Enhanced by Zemanta

Java EE 6: Using an External JPA Library in an EJB

I was looking at the NetBeans Forums for Java Enterprise Edition (EE) Development. I saw a couple of folks who were asking how I did a couple of different projects where I sent them the final result, but not an explanation of how I did it.

I decided to do a YouTube video instead of writing out how I did it. I thought the best way to demonstrate it was in a video. "A picture tells a thousand words."

Popular Posts