• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

How to initialize List property in Managed Mean?

July 12, 2008 //  by Krishna Srinivasan//  Leave a Comment

List property in Managed Mean

JSF Managed Beans can initialize its List properties in the faces-config.xml. There is a property in the faces-config.xml as list-entries. This cane be used for initializing the values and can be accessed directly through the Managed Beans in any JSP pages.

also read:

  • Introduction to JSF
  • JSF Interview Questions
  • Request Processing Lifecycle phases in JSF

You also can directly use the List as Managed Beans.

JSP File (index.jsp)

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>;
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
    <body>
        <f:view>
            <h:form>
                <h:dataTable var="loc" value="#{jsfBean.listValues}">
                    <h:column>
                        <h:outputText value="#{loc}"/>
                    </h:column>
                </h:dataTable>
            </h:form>
        </f:view>
    </body>
</html>

JavaBean (JavaBeatJsfBean.java)

package javabeat.net.jsf;

import java.util.List;

/**
 * source : www.javabeat.net
 */
public class JavaBeatJsfBean {

    private List listValues;

    public List getListValues() {
        return listValues;
    }

    public void setListValues(List listValues) {
        this.listValues = listValues;
    }
}

faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="1.2"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
    <managed-bean>
        <managed-bean-name>jsfBean</managed-bean-name>
        <managed-bean-class>javabeat.net.jsf.JavaBeatJsfBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
        <managed-property>
            <property-name>listValues</property-name>
            <list-entries>
                <value>Google.com</value>
                <value>Yahoo.com</value>
                <value>Guruji.com</value>
            </list-entries>
        </managed-property>
    </managed-bean>
    <navigation-rule>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>/index.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
</faces-config>

Category: JSFTag: Managed Bean in JSF

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « Lists and Maps as Managed Beans in JSF
Next Post: How to use Managed Bean reference inside faces-config.xml? »

Reader Interactions

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

EJB 3.0 Timer Services

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact