Lists and Maps as Managed Beans in JSF

This tips explain how to use List and Map classes directly as Managed Beans. Here notice that you cannot use List and Map interfaces directly as Managed Beans, you can use only the implementations classes like ArrayList, Map, etc. There is no way to call constructor in the interfaces if you use List or Map directly.

also read:

The following example program initialize the values in the faces-config.xml and stored as managed beans. You can use that beans directly in the JSP pages. Note that the sample program uses ‘none’ as the scope for the bean. This is because the resulted managed bean is created as per the request and will not be stored anywhere in the scopes.

JSP File (index.jsp)

<%@taglib prefix="f" uri=""%>
<%@taglib prefix="h" uri=""%>
                <h:dataTable var="loc" value="#{listBean}">
                        <h:outputText value="#{loc}" />
                <h:outputText value="#{mapBean['Apple']}"/>
                <h:outputText value="#{mapBean['Google']}"/>
                <h:outputText value="#{mapBean['Reliance']}"/>


<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="1.2"
            <value>Steve Jobs</value>
            <value>Sergy Brin</value>
            <value>Larry Page</value>
            <value>Anil Ambani</value>
                <value>Steve Jobs</value>
                <value>Larry Page and Sergy Brin</value>
                <value>Anil Ambani</value>

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!