Friday October 17, 2008
TOTD #49: Converting a JSF 1.2 application to JSF 2.0 - @ManagedBean
This is a follow up to TOTD
#48 which showed how to convert a JSF 1.2 application to use
new features of JSF 2.0. In this blog, we'll talk about a new
annotation added to the JSF 2.0 specification - @ManagedBean.
@ManagedBean is a new annotation in the JSF 2.0 specification. The
javadocs (bundled with the nightly)
clearly defines the purpose of this annotation:
The presence of this
annotation on a class automatically registers the class with the
runtime as a managed bean class. Classes must be scanned for the
presence of this annotation at application startup, before any requests
have been serviced.
Essentially this is an alternative to <managed-bean>
fragment in "faces-config.xml". This annotation injects a class in the
runtime as a managed bean and then can be used accordingly.
Using this annotation, the following "faces-config.xml" fragment from
our application:
| <managed-bean> <managed-bean-name>cities</managed-bean-name> <managed-bean-class>server.Cities</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <managed-bean> <managed-bean-name>dbUtil</managed-bean-name> <managed-bean-class>server.DatabaseUtil</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>cities</property-name> <value>#{cities}</value> </managed-property> </managed-bean> |
| @Entity @Table(name = "cities") @ManagedBean(name="cities", scope="request") @NamedQueries({@NamedQuery(...)}) public class Cities implements Serializable { |
| @ManagedBean(name="dbUtil", scope="request") public class DatabaseUtil { @ManagedProperty(value="#{cities}") private Cities cities; |
Posted by Arun Gupta in web2.0 | Comments[10]
|
|
|
|
|
Today's Page Hits: 4487
Total # blog entries: 1002
just so so
Posted by vieri122 on October 17, 2008 at 10:28 PM PDT #
Nice - but why is the scope declaration (in the @ManagedBean annotation) a string ?. Would it not be better with a ScopeType enum ?.
Anyway looking forward to cut my faces-config down to a reasonable size.
Posted by Lars Tackmann on October 19, 2008 at 03:27 AM PDT #
i just want to say it's cool!!11
Posted by 218.27.205.70 on October 24, 2008 at 03:42 AM PDT #
there is a another jsf framework AOM .it is much btter than this.
online demo
http://www.operamasks.org/rcdemos/index.jsf
Posted by vieri122 on October 24, 2008 at 05:11 AM PDT #
This is cool!
Really annotations help us improve and increase the time development.
But, what i do to configure an property HashMap?
Posted by Fred on October 25, 2008 at 02:15 PM PDT #
noriu zaisti runescape.com
Posted by arnasarnas on October 29, 2008 at 11:02 AM PDT #
Lars, follow up to your comment:
Following javax annotations have been added in the spec and Mojarra:
- @RequestScoped
- @SessionScoped
- @ApplicationScoped
- @UnScoped
Posted by Arun Gupta on December 05, 2008 at 06:01 PM PST #
very very thankss
Posted by çiçekçi on January 16, 2009 at 05:03 AM PST #
I think there is more bugs than written here.
Posted by Football Pictures on March 08, 2009 at 02:20 PM PDT #
thanks
Posted by sinema izle on March 13, 2009 at 02:17 PM PDT #