Building a simple feed reader with PrimeFaces 3.0 and Netbeans 7 (with Maven) that talks to Apache Abdera

Post to Twitter

PrimeFaces is a lightweight open source component suite for Java Server Faces 2.x. The PrimeFaces team is working on an upcoming 3.0 release which offers a lot of new functionality and components. One new component is the FeedReader. Today I’m going to demo how to use the new FeedReader to talk to Apache Abdera and to get a feed back.


For the Apache Abdera part of this demo please see the Apache Abdera Server article I did located here. I’ll use that source code to power the feed server that we will talk to with the PrimeFaces FeedReader.

Assuming now that you have the Abdera server up and running (you can populate some data into it with the Abdera Client project I created – the article is here). Make sure the Abdera server is up and running and has some data in it.

In Netbeans 7 create a new Maven Java Application.

You can name the project: PrimeFacesReader

Next we will need to add some dependencies to the POM file. You can right-click on the Dependencies folder and add them that way or you can take the code below and add it in manually. Make sure though you add the PrimeFaces repository.

I’m also going to use Jetty 8 embedded to power all of this. Keep in mind the PrimeFaces FeedReader has a dependency on Rome.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.giantflyingsaucer</groupId>
    <artifactId>PrimeFacesReader</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>    

    <name>PrimeFacesReader</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <repositories>  
        <repository>  
            <id>prime-repo</id>  
            <name>PrimeFaces Maven Repository</name>  
            <url>http://repository.primefaces.org</url>  
            <layout>default</layout>  
        </repository> 
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.0.1.v20110908</version>
        </dependency>
        
        <dependency>  
            <groupId>org.primefaces</groupId>  
            <artifactId>primefaces</artifactId>  
            <version>3.0.M3</version>
        </dependency>
        
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.1.3_01</version>
        </dependency>
        
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.1.3_01</version>
        </dependency>
        
        <dependency>
            <groupId>net.java.dev.rome</groupId>
            <artifactId>rome</artifactId>
            <version>1.0.0</version>
        </dependency>
        
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>8.0.1.v20110908</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webAppConfig>
                        <contextPath>/</contextPath>
                    </webAppConfig>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Right-click on the Web Pages folder now and add a new JSF file called index (the xhtml extension will be added automatically). You can delete the JSP page that was generated when you created the project. Your project should look like this:

The contents of the index.xhtml file are as follows:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.prime.com.tr/ui">

	<h:head>
	</h:head>
	
	<h:body>	
        <p:feedReader value="http://localhost:9003/employee" size="10" var="feed">  
            <h:outputText value="#{feed.title}" style="font-weight: bold"/>  
            <br />
            <h:outputText value="#{feed.author}"/>
            <p:separator />  
        </p:feedReader>	
	</h:body>
</html>

Results:

Very simple, nothing fancy. Obviously you can do much more if you wish but this is the basics to get you going.

Post to Twitter

This entry was posted in Apache Abdera, Java, Netbeans. Bookmark the permalink.