On Java Development

All things related to Java development, from the perspective of a caveman.

Use Spring to load a SelectOneMenu

without comments

Introduction

This post shows how to use Spring to load a JSF SelectOneMenu component. The values for the menu are placed into a simple POJO by Spring which is then referenced by the SelectOneMenu component for loading.

 

The POJO

Shown below is a very simple POJO that provides the necessary setter and getter methods need to set and retrieve values that have been provided as an array of String objects.

 

The Spring bean definition

Shown below is the bean definition for the POJO defined above. It has been placed into the applicationContext.xml file that is part of baseproject. When the application is started, the entry shown will initialize the bean with the list of machine names.

 

The ManagedBean’s Initialization Process

To ensure the loading of the SelectOneMenu is performed only once, the Java code shown below is placed into the Managed Bean’s @PostConstruct method used to initialize the bean. After the for-loop completes, the listOfMachineSelectItems object is placed into the session bean object.

 

The JSF Code for the SelectOneMenu

The method called by the JSF code above:

 

Showing The SelectOneMenu Options

The prompt below presents the SelectOneMenu complete with the entries defined by the Spring bean definition.
SelectOneMenuMachines

Written by admin

December 10th, 2014 at 11:17 am

Leave a Reply

You must be logged in to post a comment.