On Java Development

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

A ManagedBean Class Template

without comments


This post presents what amounts to being an empty Java class designed to act as a starting template for a Managed Bean that is associated with a JSF page. This post highlights the parts that are common to classes of this nature and a few of the not-so-obvious aspects of coding Managed Bean classes.


The Managed Bean

Presented below is the code for the Managed Bean class called Page04ManagedBean. As the name implies, it is designed to be used as the 4th in a series of pages. Its selection for this post is arbitrary. Other than the role they play for the JSF page, there are no major differences between each Managed Bean.

Right away, you may have noticed there are a couple of methods that have some code for them as well as comment banners designed to segregate methods that are common among themselves as determined by the kind of tasks they are designed to implement.


The Methods

Below is a brief description of the methods supplied by this template.

  • public void processPageLoadEvent() – As the comments indicate, this method is designed to be called when the page is first rendered and is controlled by the @PostConstruct annotation.
    The code on line 26 is calling the ApplicationContextManager class that is included in baseproject. The method getApplicationGlobalPropertiesBean() is pulling the defined bean from the Spring context and the method isPage04Initialized() returns a boolean, TRUE or FALSE. This controls the execution of the if-group that follows and is where any “one-time-only” type of code is to be placed. Examples of such code is represented by the logic needed to collect any records needed to populate a data table, a very common activity of web pages. Think of this method as the *INZSR method of an RPG program.

    The code on line 32 represents the last bit of logic to be executed for this if-group. After the boolean has been set to TRUE, the logic again uses the ApplicationContextManager to write the value back into the bean defined to Spring. This is the mechanism used to preserve the state indicator so that the page loading process occurs only once for the lifetime of the page.

  • public void gotoPage01(ActionEvent event) – This method performs the logic needed to navigate to a specific web-page. In this case, the logic will present the first page of the application. It is also again using the ApplicationContextManager to manage page state booleans.


Comment Banners

These are simply loud markers to make it easy to identify certain areas of the class where certain types of methods are to be placed.

  • Property Accessors and Mutators – The role of accessors and mutators are to set and return the values of an object’s properties.
  • Action Methods – These are methods that are associated with the web-page’s components.
  • Helper methods – General use or so-called “helper” methods.
  • Navigation – Navigation methods.



This post presented a template class to be used as a Managed Bean and illustrated some of the concerns to be addressed through the use of annotations and beans stored in Spring’s context.

Introduction to JSF
Annotation Type PostConstruct

Written by admin

July 2nd, 2014 at 8:55 am

Leave a Reply

You must be logged in to post a comment.