Tuesday, December 23, 2008

Comparison of JSF / Java Servlet and asp.net lifecycle and events (similarities, differences)

Asp.net applications similar to JavaEE web apps have application events, and we can configure listeners/handlers for those events.
For a Java web app, the following events can be handled by wiriing up our listeners in the web.xml file (web deployment descriptor) (Ref: http://edocs.bea.com/wls/docs61/webapp/app_events.html#177041)
1) Application startup
2) Application shutdown
3) Session creation
4) Session invalidation/passivation
5) Session level attribute added/removed/replaced
6) Servlet attribute added/removed/replaced
JSF lifecycle events for a jsf page: (Listeners/Handlers are defined as PhaseListeners)
Similar to the IIS engine which passes the aspx request to a HttpHandler in a asp.net engine, the JavaEE app container (Tomcat, JBoss, WebLogic) passes the jsf request to the JSF Servlet (FacesServlet). The FacesServlet then goes through the below lifecycle events (the PhaseListener can execute code before and/or after a phase): 
 
1) Restore_View
2) Apply_Request_Values (can process events and exit lifecycle)
3) Process_Validations (can process events and exit lifecycle)
4) Update_Model_Values (can process events and exit lifecycle)
5) Invoke_Application (can process events and exit lifecycle)
6) Render_Response
  1. Servlet Context events: 1) Servlet Context created - javax.servlet.ServletContextListener.contextInitialized() 2) Servlet Context about to be shut down - javax.servlet.ServletContextListener.contextDestroyed() 3) Attribute added - javax.servlet.ServletContextListener.attributeAdded() 4) Attribute removed - javax.servlet.ServletContextListener.attributeRemoved() 5) Attribute replaced - javax.servlet.ServletContextListener.attributeReplaced()
  2. HTTP Session events: 1) Http session activated - javax.servlet.http.HttpSessionListener.sessionCreated() 2) Http session about to be passivated - javax.servlet.http.HttpSessionListener.sessionDestroyed() 3) Attribute added - javax.servlet.http.HttpSessionListener.attributeAdded() 4) Attribute removed - javax.servlet.http.HttpSessionListener.attributeRemoved() 5) Attribute replaced - javax.servlet.http.HttpSessionListener.attributeReplaced()
For a ASP.net web application: the below lifecycle-events (in order): 
(Ref: Pro asp.net 2.0 in C# 2005 from Apress)
These events occur for every request. Here an aspx page request is discussed.
The systems/actors in action here are the IIS engine (inetinfo.exe), and the asp.net engine (aspnet_wp.exe). The event handlers/listeners are registered/defined in the global.asax file.
1) Application_BeginRequest
2) Application_AuthenticateRequest
3) Application_AuthorizeRequest
4) Application_ResolveRequestCache
5) At this stage the http request is handed off the appropriate HttpHandler, e.g. for an aspx request it is passed to the asp.net engine (aspnet_wp.exe), where the page is compiled (if necessary) and instantiated. 
6) Application_AcquireRequestState
7) Application_PreRequestHandlerExecute
8) At this stage, the appropriate handler executes the request,e.g. for an aspx request, the event-handling code for the page is executed, page rendered to HTML, i.e. the ASPX page lifecycle is executed (start, init, load, validate/control events, postback, loadComplete, preRender, saveViewState, render, unload
9) Application_PostRequestHandlerExecute
10) Application_ReleaseRequestState
11) Application_UpdateRequestCache
12) Application_EndRequest
Asp.net application events:
These events do not always occur, they are triggered by the application or code.
These are commonly used to perform app initialization, cleanup, usage/stats logging/monitoring, profiling, and troubleshooting. 
1) Application_start
2) Session_start
3) Application_error
4) Session_end
5) Application_End
6) Application_Disposed
Asp.net aspx pafe lifecycle events:
This lifecycle is executed inside the asp.net engine (aspnet_wp.exe) for each aspx page. 
1) Page_Start
2) Page_PreInit
3) Page_Init
4) Page_InitComplete
5) Page_PreLoad
6) Page_Load
7) Process Control events/postback 
8) Page_LoadComplete
9) Page_PreRender
10) SaveStateComplete
11) Page_Render
12) Page_RenderComplete
13) Page_Unload

No comments:

Post a Comment