Java and JSF howto blogs and code snippets

Using Google Custom Search engine in PrimeFaces Overlay Panels

Posted on Thursday February 20, 2014 23:59:02
Filed under HTML/JS/CSS category

The following is an example on how to implement a custom Google Search engine in PrimeFaces version 4 <p:overlayPanel />. First create an account with Google Custom search (CSE) here https://www.google.com/cse. You will get your own Custom Search engine ID. From within your CSE account you will find a place to generate the following basic CSE Javascript code. Place this code in the head section or in the body just before the closing </body> tag, whichever is prefered.

Read complete article

A dynamic standard sitemap.xml with Google image extension implemented as a Java Servlet

Posted on Thursday March 07, 2013 00:57:25
Filed under Java/JSF category

A sitemap.xml generated on demand is very helpful for websites that has lots of pages and with pages that are added frequently. According to Google, sitemaps help their crawlers find pages from websites. This is true for new websites or for pages that has fewer links to them.

The servlet herein described is based on sitemaps.org protocol with Google image extension. We used JDOM2 library to create the XML sitemap structure. Below is how a standard sitemap looks like with the Google image extension. Please note that image extension is supported only by Google. Bing/Yahoo ignores them.

Read complete article

Generating XML RSS 2 feeds with JDOM 2 with a servlet

Posted on Thursday January 31, 2013 20:03:52
Filed under Java/JSF category

To better demonstrate how to generate XML RSS 2 feeds, we will use a servlet with JDOM 2 library. In this short blog, we will generate only the required elements plus a few options for feed reader interoperability. Please refer to the RSS 2 documentation for more of the optional elements and to learn more about the RSS 2 specifications. JDOM 2 is available for download here http://www.jdom.org/.

Below is a sample RSS 2 feed generated by the servlet that follows further down (contents edited for clarity).

Read complete article

Implementing a collapsible ui:repeat rows in JSF

Posted on Wednesday December 19, 2012 20:35:45
Filed under Java/JSF category

Here is simple implementation of a JSF <ui:repeat /> component with collapsible rows with the aid of JQuery.   It is very simple, no specials tricks, except that the components inside <ui:repeat /> must have a unique ID (or class) which is handled by the backing code.  Toggling the visibility of the frame (<div />) is taken cared of by the onclick event on the link, in this case <h:outputLink />

Read complete article

Using Rhinoslider with image and youtube content in JSF pages

Posted on Saturday May 04, 2013 18:44:17
Filed under HTML/JS/CSS category

Rhinoslider demo   
Rhinoslider sample.   
Rhinoslider is a beautiful JQuery slider plugin that can handle images, video and other HTML content with many custom options. Using the plugin in HTML pages is quite simple and straightforward. Their website even has a generator that will give you a code and start customizing the plugin from there. Here in this blog, we will demostrate how to integrate this plugin on images and youtube videos into a JSF page based on version 1.05 of the plugin. We will provide 2 options of embedding the plugin. Live demo is available in the home page with this site.

Listing 1 below, is a sample generated page. Please make sure that items from 6 to 11 of the snippet are accessible from the page itself. These items are part of the plugin download. If using PrimeFaces, you may want to remove lines 6 to 8. Also lines 10 and 11 are optional and are controlled by the values of "easing" and "controlsMousewheel" parameters of the plugin (see Listing 7).

Read complete article

Creating a Facebook-like panel with slim scrollbars and infinite scrolling in PrimeFaces

Posted on Friday February 08, 2013 16:40:40
Filed under Java/JSF category

Some of the Facebook panels with slim scrollbars and infinite scrolling are those non full-page panels used to display notifications and messages. These are activated by button-icons in the upper left corner of your timeline. In this blog, we will demonstrate how to create similar panels using slimScroll jQuery plugin in PrimeFaces.

Please note that the first section of this blog (slimScroll panel without the infinite scrolling) also works for standard JSF projects.

Read complete article

Building a page with infinite scroll in PrimeFaces using Waypoints jQuery plugin

Posted on Friday December 21, 2012 22:55:02
Filed under Java/JSF category

Infinite scroll is a page feature where in data is automatically loaded as you scroll down to the bottom of a page. Facebook uses this feature in their "news feeds".

This demonstration uses PrimeFaces with a jQuery plugin called WayPoints.  Plugin download and documentation can be found here http://imakewebthings.com/jquery- waypoints/.  We employed PrimeFaces' <p:remoteCommand /> and <p:outputPanel /> along with Waypoints, the main component of the process.   It is Waypoints that initiates the update process that call <p:remoteCommand />, and in turn into the backing code, as soon as a Waypoint element appears at the bottom of the page/viewport.

Read complete article

Validating an email address in PrimeFaces p:inputText field with p:ajax

Posted on Tuesday December 04, 2012 15:33:33
Filed under Java/JSF category

The example that follows demonstrates how to validate an email address inputted from a PrimeFaces <p:inputText /> field.  It validates the correctness of the email address as well as its existence.  PrimeFaces version 3.4.1 was used to test this demonstration.

Read complete article