For every place you want to customize put a "ui:insert" instruction with an attribute "name". The body of <u:insert can be overridden from a composition using <ui:define

<ui:insert without a body has simply no default value

Example :
To use the previous example "layout.xhtml" as a template and customize the header of every composition (file that uses the template) :

Add <ui:insert with a body. The same name attribute, will be used in the composition to override the body (with the instruction <ui:define). Note that the styling instruction (h1) is now outside <ui:insert>. If you do not provide a <ui:define name="header" the template will use the default <ui:insert> body. The same thing is done for <title>

Note:
All parties of "layout.xhtml" that are not customized by <ui:isert> stay as is.
The header has now changed.

Display

Note:
In the same way, we can create another composition that uses the template with another custom header. Another composition for instance index.xhtml that does not provide a <ui:define name="header" will still use the default header value defined in the template.

To create a template
=====================
-Insert a namespace instruction
xmlns:ui="http://java.sun.com/jsf/facelets"

-For every place you want to customize put a "ui:insert" instruction with an attribute "name".
This <ui:insert is replaced with the value of a <ui:define in a composition
The body of <u:insert can be used as a default text, if the <ui:define for the same name attribute is absent

How to create a composition
============================
-Use <ui:composition to define a composition. "template" attribute's value is the full path to the template to be used.
(with .xhtml extension)
-Use a namespace : xmlns:ui="http://java.sun.com/jsf/facelets"
-Inside the composition tag, use <ui:define to override, or replace every <ui:insert you want to customize in the template.

-You can use <ui:include> inside <ui:define to include a composition. "src" is the path to the file with .xhtml extension

>> 16 November 2010

On Google App Engine, many of the classes used in Java for drawing or displaying images are restricted classes (Not on GAEJ white list). A partial solution is to use Google's dedicated Images service. Another solution is to use for instance another framework for images with permitted classes. Google has an elegant library for visualizing data, like charts among other interesting visualizations. Using this visualization API is pretty straightforward, here is a step by step example

How to use Google Visualization API

Begin by loading some Javascript libraries, there are 3 to load.

Google AJAX API
This library must be loaded first.
Is used to load other libraries and handle some core functionality such as event handling.
Defines the google.load() and google.setOnCallback()
<script type="text/javascript" src="http://www.google.com/jsapi"></script>

Google Visualization API core
Common classes and methods used to create and handle visualizations (DataTable, query object, error handlers),
All is in google.visualization namespace.
Loading this library is combined with the third one.

A library for each type of visualization
Each one is a specific visualization (for example, a pie chart or a line chart)
Is a JavaScript class that exposes methods specific to that visualization, plus a few common methods and events (such as draw() and select). <script type="text/javascript"> // Load the Visualization API and the piechart package. google.load('visualization', '1', {'packages':['corechart']});

Prepare your data.
specifying the data yourself in code,
or querying a remote site for data.

Create an instance of your visualization.
Instantiate your visualization by calling its constructor and passing in a reference to your <div> element (see later).

Draw your visualization.
Call draw() on your visualization and pass in your data to draw your visualization on the page.

Options.
There are various other optional actions, such as handling user events or specifying visualization options.

Example 2Adding a progress bar (busy bar)
First of all we add a function in JavaScript section, this function will be called when an Ajax event is launched. It received an argument "data", or any other name. The variable "data.status" gives information about the progression of the Ajax request. If this variable's value is "begin",the request is sent and the program is waiting for the response. In this case we display any image to let the user wait. If the variable has any other value like "success" or "complete" the request has ended, so we can hide the busy image and display the chart. Javascript function is a callback function triggered by "onevent" attribute in the Ajax call.

I've added a sleep call, only to simulate long call on the development server

Note:
prependId="false" of the form is used to split components ID from the form's ID. Like this we can the given ids without using the form's associated id.

Example 3Persist our data
To persist the data, I'll use some JDO annotations in the ManagedBean to persist and retrieve data from the Datastore. A method "init" annotated "@PostConstruct" is called only once, after the construction of the bean's object. PMF is a singleton used to get a PersistenceManagerFactory instance. A better example for persisting would be for instance to add a button and verify the user's IP, instead of persisting and updating as a response to selecting <h:selectOneRadio.

This library looks very interesting and powerful. Here is a Hello World.

ZXing ("Zebra Crossing")

The description is from the library's site
"ZXing (pronounced "zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in Java. Our focus is on using the built-in camera on mobile phones to photograph and decode barcodes on the device, without communicating with a server."

Project's Site :
http://code.google.com/p/zxing/

Installing

Download the current version (Zxing-1.6.zip)

Unzip in a folder of your choice, this will give "zxing-1.6" folder

For normal Java programs, two .jar files must be built

One of the possibilities is to use "ant"

cd zxing-1.6/core

Type "ant" you'll get in the same folder "core.jar"

cd zxing-1.6/javase

Type "ant" you'll get here "javase.jar"

In your Java project, create a folder (give it any name), for instance "lib"

3.Import the namespace, by instruction in .xhtml page
"xmlns:p="http://primefaces.prime.com.tr/ui"

Web Site :
http://www.primefaces.org/

Will it play on GAEJ
Yes. Except for some special operations where other libraries are used. Some of these use dependencies that are not on the "The JRE Class White List" of Google, for instance Jcomponent when generating bar code with "Barbecue".

Hello Calendar

To change a bit of the famous "Hello World", I'll try here a calendar (one of the components provided by PrimeFaces)

2.Unzip the downloaded theme file (zip) into a folder in your application (I Used in the example "ui-lightness" the full path to the unzipped folder is "war/primeFacesThemes/ui-lightness/")
3.In any .xhtml put a link to the css file

>> 23 September 2010

Generating PDF from your Java programs is nowadays possible and easy, thanks to iText a free/Open Source project (you can also have a commercial license).

IText let you (between other things) generate PDF documents and save these as ordinary .pdf file from any Java program. It can also generate a PDF document on the fly, this one, for instance can be served from a servlet.

In this tiny tutorial, I'll generate a .pdf file from a Java program.

Note about GAEJ
In older versions of iText, some dependencies were not on the "The JRE Class White List" of Google. In this version (and maybe in other recent versions), this problem was likely solved and restricted class exception is now over, or at least in the code i've been testing for the last couple of days (simple PDF documents).

Official site of iText

http://itextpdf.com/

Download site

http://sourceforge.net/projects/itext/files/

Download iText

itext is available as .jar file (the current version is 5.0.4)

Installing

If you use a Java project (In Eclipse for instance), just create a folder of your choice in the project (in the example I called it "lib"), copy "iText-5.0.4.jar", to "lib" folder.