JavaServer Faces and ASP.NET - A Side by Side Look, Page 3
The faces-config file is also where you list all JavaBeans associated with your JSP page file. In fact, this is where you can configure any Java objects your application needs to reference. These Java objects are referred to as 'managed beans'. All JSF backing beans will be listed as managed beans in this configuration file, but any other objects you need will be found here too. A managed bean contains the fully qualified class name, the scope of the bean (whether to store it at the Request, Session, or Application level of the application), and the name to use when referencing the bean. In the XML below, the backing bean for the starting web page is listed as well as an entry for an EJB (Enterprise JavaBean) called ReservationsSessionBean that we use to share data in the application:
<managed-bean> <managed-bean-name>ReservationsSessionBean</managed-bean-name> <managed-bean-class>webreservations.ReservationsSessionBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> <managed-bean> <managed-bean-name>ConferenceRooms</managed-bean-name> <managed-bean-class>webreservations.ConferenceRooms</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean>
Back to the application, our request to view reservations takes us to RoomReservations.cs.aspx for the ASP.NET version, and RoomReservations.jsp for the JSF version. In the associated code files, RoomReservations.cs and RoomReservations.java, the event code retrieves the room id stored in the previous page and uses it to filter a second table that lists reservations for that room. The label above the data table is modified to reference the name of the room.
A delete button accompanies each row of data. Both of these components allow you to modify table data with very little effort. Last, each form contains a button which takes you to a form for adding a new reservation for that room. These forms appear below. These were created quickly by dragging and dropping a text field for the name of the group reserving the room, two calendar components for selecting the start and end times of the reservation, and a button to save the reservation. The calendar components provided by Java Studio Creator and Visual Studio display differently, but serve the same purpose.
At this point, we need to have the user enter some data and deal with the issues that arise when accepting user input, validation for example. My next article will take up where we left off here. In it, we will look at other issues most applications face such as validating input, converting data, providing error messages, and internationalization.
About the Author
Michael Klaene is a Senior Consultant with Sogeti LLC. He has spent over 7 years in IT, specializing in J2EE and Oracle analysis and development.