Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Struts Wiki" for change 
notification.

The following page has been changed by MichaelJouravlev:
http://wiki.apache.org/struts/StrutsManualActionWebComponent

------------------------------------------------------------------------------
  #format wiki
  #language en
  
- Struts 1.4 allows building portlet-like web components using JSP as view 
technology. The components work properly with or without Javascript enabled.
+ Struts 1.4 allows building portlet-like web components using JSP as view 
technology. ''Struts web component'' is an independent server-side object that 
accepts user input via Action class, and renders itself via JSP file. In a 
sense, Struts web component is a simple portlet.
  
- Struts Components have the following features:
+ Struts approach to web components has the following features:
  
     * Allows composing a page out of one or more independent components.
     * Renders a view that is always synchronized with application state.
@@ -16, +16 @@

     * Updates page incrementally without full page refresh if browser has 
Javascript turned on and XMLHTTPRequest is available.
     * Seamlessly integrates with Struts, enhancing a well-known action 
framework with component technology.
  
- == Struts Component Lifecycle ==
+ == Struts Component Lifecycle In Synchronous Mode ==
  
- ''Struts web component'' is an independent stateful server-side object that 
accepts user input via Action class, and renders itself via JSP file.
- 
- The component lifecycle is managed in a five-step process:
+ In synchronous mode the component lifecycle is managed in a five-step process:
  
     1. The cycle begins with the initial load of a composite page, starting 
the render phase.
     2. When the JSP processor encounters a <c:import> action in a composite 
page, it generates an HTTP request to obtain the content of the included 
component.
@@ -28, +26 @@

     4. The user initiates the input phase by submitting an HTML form or by 
activating a command link. The browser sends input data to an Action that 
manages component events and state. The Action processes data and updates 
component state if needed. Component state can be stored in a session-scoped 
form bean, in a database or in other location.
     5. After input data has been processed, the Action automatically redirects 
to location of the composite page, effectively switching from input phase back 
to render phase. Steps 1 through 3 are repeated, and an updated page is 
presented to the user.
  
- inline:action_component.gif
+ inline:action_component_title.gif
  
- If the browser has !JavaScript turned on and the XMLHTTPRequest object is 
available, the component switches to Ajax mode by making an asynchronous 
request to update the component without full page refresh, so steps 5, 1, and 2 
are skipped, and step 4 jumps right to step 3. The incremental update is more 
effective in regards to network traffic and avoids the complexities of 
identifying the reload address.
+ == Struts Component Lifecycle In Asynchronous Mode ==
  
+ If the browser has !JavaScript turned on and the XMLHTTPRequest object is 
available, a web component is updated asynchronously; steps 1, 2 and 3 do not 
differ from synchronous mode:
+ 
+    1. The cycle begins with the initial load of a composite page, starting 
the render phase.
+    2. When the JSP processor encounters a <c:import> action in a composite 
page, it generates an HTTP request to obtain the content of the included 
component.
+    3. The Action class forwards to a view relevant to component state. After 
all components on the composite page have rendered themselves, the render phase 
finishes and a composite page is presented to a user.
+    4. The user initiates the input phase by submitting an HTML form or by 
activating a command link. '''Javascript engine sends input data to the Action 
asynchronously using XMLHTTPRequest object.''' The Action processes data and 
updates component state if needed. Component state can be stored in a 
session-scoped form bean, in a database or in other location.
+    5. '''After input data has been processed, the Action forwards to a view 
relevant to component state. This view is returned to the browser in response 
to asynchronous request. The Javascript engine finds the spot in the composite 
page where the component resides, and updates page fragment in place.''' The 
user sees an updated page.
+ 
+ inline:action_component_ajax_title.gif
+ 
- A Struts component incorporated into a page looks and behaves uniformly 
whether it runs in Ajax mode or not. The dual-mode functionality of Struts web 
components is invaluable for environments where !JavaScript is not allowed or 
in browsers that do not support the XMLHTTPRequest object, like some mobile 
browsers.
+ A Struts component incorporated into a page looks and behaves uniformly 
whether it runs in Ajax mode or not. The dual-mode functionality of Struts web 
components is invaluable for environments where !JavaScript is not allowed or 
in browsers that do not support the XMLHTTPRequest object, like some mobile 
browsers. 
+ 
+ It is worth noting that both Ajax and non-Ajax modes utilize the same code 
and markup.
  
  == Use Case: Home Page With Login Component ==
  
+ Consider the following use case: a website has a home page that should have 
different content for regular visitors one one hand, and for logged in users 
for another hand. The page contains login/logout form. A non-logged-in user 
must be presented with login, while a logged-in user should be able to log out.
- Consider the following use case: a website has a home page that should have 
different content for regular visitors one one hand, and for logged in users 
for another hand. The page contains login/logout form, a user must be presented 
with login form if he is not logged in yet. Those users who logged in must be 
able to see information about themselves and must be able to log out.
- 
- inline:login-component.gif
- 
- While implementing this use case the login/logout widget must reload the 
whole page if login attempt fails. Also, login/logout widget must have explicit 
knowledge about the target location, in our case it has to know the address of 
the home page. Therefore, it is nearly impossible to develop an independent 
login/logout widget that can be inserted into different pages and just work. 
Well, it is possible now. 
  
  == Component Configuration ==
  

Reply via email to