How to create a Managed bean in JSF 2

 

Managed bean is similar to Java bean class; it contains setter-getter methods and business logics. We could use the managed bean variables directly in the JSF pages. A normal java bean becomes a managed bean by mentioning annotation @managedbean on top of the class. This section we have described an example of creating a managed bean in JSF 2 and use the bean variable in the JSF page.

 

Create a Managed Bean Class (Happyday.java)

We have created a managed bean with a getter method which returns a text “Hello Timon!”. The ‘@ManagedBean’ makes this class as managed bean.

 

 

 

Create a XHTML file under WebRoot (index.xhtml)

 

We have referred the Managed bean variable text in this XHTML file by using EL expression #(CLASSNAME.GETTERMETHOD),that is #{happyday.text}

 

 

 

Deploy the Project and test it in browser

 

022516_0239_SimpleJSF2M1 How to create a Managed bean in JSF 2

 

Download Sourcecode:  Managed Bean in JSF 2 example


govindan How to create a Managed bean in JSF 2
Connect me

Govind

Thank you for visiting my personal blog. Myself Govindan, Software Developer by profession since 2006 and hence I started this blog early in 2016 and ever since I've been writing about technologies experienced and learnings of everyday life.

The views expressed on this blog are my personal views and do not necessarily reflect the views of my employer.

Please feeling free to reach me on any comments and feedbacks you have. Would be more than glad to listen and reply šŸ™‚
govindan How to create a Managed bean in JSF 2
Connect me
By | 2017-06-07T00:36:08+00:00 February 24th, 2016|Categories: JSF|Tags: |0 Comments
Like us on Facebook.
Connect!