Creating Lists and Maps as Managed Beans in JSF

This example explains how to use Lists and Maps as Managed Beans in JSF. It is recommend to put the managed beans in a separate managed-beans.xml file to keep a clear overview of managed beans that have been registered with xml in our application.

Configuring Lists and Maps as managed beans in JSF


We can configure Lists and Maps as Managed Beans using JSF. We assign a name that we can use in the view to reference the bean. We must provide an implementation class of the Map or List because JSF cannot choose an implementation at runtime.

Note: that the sample configuration uses ‘none’ as the scope for the bean. This is because the managed bean is created per request and will not be stored anywhere in any scope.

<faces-config xmlns=""
                        " version="2.2">


                <key>La Chouffe</key>


Registering the managed-beans.xml in the Servlet Descriptor


The javax.faces.CONFIG_FILES initialization parameter tells JSF where to look for configuration files. So if you created a separate managed-beans.xml file you must register that file in this parameter, as described below.

<web-app xmlns=""
                   " version="3.1">


    <!-- Change to "Production" when you are ready to deploy -->

    <!-- Welcome page -->

    <!-- JSF mapping -->
        <servlet-name>Faces Servlet</servlet-name>

    <!-- Map these files with JSF -->
        <servlet-name>Faces Servlet</servlet-name>


Displaying Managed Lists and Maps

We can reference the map and list we created using the managed-bean-name from the managed beans configuration file.

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns=""

    <h1>JSF List Map Managed Beans</h1>

    <h3>JSF List Managed Bean</h3>
    <h:panelGrid columns="2">
        <h:outputLabel value="Colors: "/>
        <h:outputText value="#{colors}"/>

    <h3>JSF Map Managed Bean</h3>
    <h:panelGrid columns="2">
        <h:outputLabel value="Beers: "/>
        <h:outputText value="#{beers}"/>



URL: http://localhost:8080/list-map-managed-beeans-jsf/

lists and maps as managed beans in JSF



You may also like...