Advertise with us

Our eBooks

Richfaces Java EE 6 application

Upgrading your web page

The changes required to your web page are, at first the namespace declaration under which Richfaces UI components will be executed. This boils down to adding this declaration at the top of your page:

<ui:composition xmlns=""


So this is your Web page engineered for Richfaces 4:

<ui:composition xmlns=""




            <rich:panel header="Richfaces sample"

                <h:outputText value="Enter key:" />
                <br />

                <rich:autocomplete value="#{manager.key}" minChars="1"
                    autocompleteMethod="#{manager.autoComplete}" />
                <br />
                <h:outputText value="Enter value:" />
                <br />
                <h:inputText value="#{manager.value}" />
                <br />
                <br />

                <h:commandButton actionListener="#{}"
                    styleClass="buttons" value="Save key/value" />
                <h:commandButton actionListener="#{manager.clear}"
                    styleClass="buttons" value="Clear cache" />

                <h:messages />


            <br />
            <rich:dataTable value="#{manager.cacheList}" var="item"
                styleClass="table" headerClass="table-header"
                    <f:facet name="header">Key</f:facet>
                    <h:outputText value="#{item.key}" />
                    <f:facet name="header">Value</f:facet>
                    <h:outputText value="#{item.value}" />


As for the other components of your application, we have added two small upgrades:

  1. The autoComplete, which is used to provide a taste of the auto-completion feature to your form:
  2. A size constraint on the "key" field.

package com.sample.bean;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.validation.constraints.Size;

import com.sample.ejb.SingletonBean;
import com.sample.model.Property;

public class PropertyManager {
    SingletonBean ejb;

    ArrayList  cacheList  = new ArrayList ();

    @Size(min=3, max=12,message="Key must be between 3 and 12 chars")
    private String key;
    private String value;

    public String getKey() {
        return key;

    public void setKey(String key) {
        this.key = key;

    public String getValue() {
        return value;

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

    public void save() {
        ejb.put(key, value);

    public void clear() {

    public List<Property> getCacheList() {
        return ejb.getCache();
    public List autoComplete(String prefix) {
        List list = new ArrayList();
        for (Property element: getCacheList()) {
        return list;


Request your page with http://localhost:8080/as7richsample/home.jsf

This would produce the following page (see autocomplete in action):

jboss richfaces tutorial

In case, you would insert an invalid key size, the message will prompt in the message area:

rochfaces 4 tutorial

Fine. You have completed another session of your Java EE 6 training.

You can download the code for this article from here

© 2021 All Rights Reserved.

Please publish modules in offcanvas position.