Close

PrimeFaces - Using FeedReader to Display RSS Feed

[Last Updated: Dec 20, 2017]

This example shows how to use Primefaces FeedReader component to display RSS feed.

Additional Dependency

We need ROME dependency for FeedReader to work.

pom.xml

<dependency>
   <groupId>net.java.dev.rome</groupId>
   <artifactId>rome</artifactId>
   <version>1.0.0</version>
</dependency>

JSF page

src/main/webapp/index.xhtml

<h:body>
    <h2>PrimeFaces - RSS Feed Reader</h2>
    <p:feedReader value="http://localhost:8080/example-feed.xml" var="feed">
        <h:outputText value="#{feed.title}" style="font-weight: bold"/>
        <br/>
        <h:outputText value="#{feed.description.value}"/>
        <br/>
        <h:outputLink value="#{feed.link}">#{feed.link}</h:outputLink>
        <br/>
        <p:separator/>
        <f:facet name="error">
            Something went wrong.
        </f:facet>
    </p:feedReader>
</h:body>

Example Feed

src\main\webapp\example-feed.xml

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
  <channel>
    <title>Logicbig Tutorials</title>
    <link>http://www.logicbig.com</link>
    <description>Logicbig tutorials feed</description>
    <item>
      <title>Spring Framework</title>
      <link>http://www.logicbig.com/tutorials/spring-framework</link>
      <description>Spring Framework Quick Tutorials with Examples</description>
      <pubDate>Thu, 21 Dec 2017 03:38:50 GMT</pubDate>
    </item>
    <item>
      <title>Java EE</title>
      <link>http://www.logicbig.com/tutorials/java-ee-tutorial</link>
      <description>Java EE Tutorials and Examples</description>
      <pubDate>Thu, 21 Dec 2017 03:38:50 GMT</pubDate>
    </item>
    <item>
      <title>Java Core</title>
      <link>http://www.logicbig.com/tutorials/core-java-tutorial/</link>
      <description>Core Java Tutorials and Examples</description>
      <pubDate>Thu, 21 Dec 2017 03:38:50 GMT</pubDate>
    </item>
  </channel>
</rss>

To try examples, run embedded tomcat (configured in pom.xml of example project below):

mvn tomcat7:run-war

Output

Example Project

Dependencies and Technologies Used:

  • primefaces 6.1 primefaces
  • jsf-api 2.2.14: This is the master POM file for Oracle's Implementation of the JSF 2.2 Specification.
  • jsf-impl 2.2.14: This is the master POM file for Oracle's Implementation of the JSF 2.2 Specification.
  • rome 1.0.0: All Roads Lead to ROME. ROME is a set of Atom/RSS Java utilities that make it easy to work in Java with most syndication formats. Today it accepts all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0), Atom 0.3 and Atom 1.0 feeds. Rome includes a set of parsers and generators for the various flavors of feeds, as well as converters to convert from one format to another. The parsers can give you back Java objects that are either specific for the format you want to work with, or a generic normalized SyndFeed object that lets you work on with the data without bothering about the underlying format. [Description from rome-1.0.0.pom]
  • JDK 1.8
  • Maven 3.3.9

PrimeFaces RSS Feed Reader Example Select All Download
  • feed-reader-example
    • src
      • main
        • webapp
          • index.xhtml

    See Also