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. ''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 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 portlet.
+ 
+ A Struts Web Component is a combination of:
+  * one Action class that handles input events and updates component state;
+  * an optional form bean that holds input/output data;
+  * one or more views that can be represented with one or more JSP files.
  
  Struts approach to web components has the following features:
  
@@ -48, +53 @@

  
  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.
  
+ The picture below illustrates this use case. Of course, since it is just an 
example, the login component is almost as large as the composite page itself, 
but the idea is the same: to design a component that does not have to know the 
location of a composite page it is included into.
+ 
+ inline:login-component-sm.gif
+ 
+ = Building A Synchronous Component with Struts 1.4 =
+ 
+ The first exercise is building a synchronous, non-Ajax component. It is 
simpler than Ajax component because we do not need to fiddle with Javascript. 
On the other hand, it is more complex because instead of simply replacing one 
piece of page with another we need to figure out the location of original 
composite page and then to redirect to that location in order to reload the 
whole page.
+ 
  == Component Configuration ==
  
- The Struts Web Component is represented with one Action class and with one 
(or more) JSP pages. Let us define the Login Component in struts-config.xml 
file:
+ First let us define the Login Component in {{{struts-config.xml}}} file:
  
  {{{
  <struts-config>
@@ -69, +82 @@

        <!-- Login component -->
        <action component = "Login"
                view = "/login-struts/loginComponent.jsp"
-               path = "/loginintegrated"
+               path = "/logincomponent"
                type = "samples.login.LoginAction"
                form = "loginform"
                scope = "session"
@@ -82, +95 @@

  </struts-config>
  }}}
  
- Notice new action mapping attributes and properties:
+ Notice action mapping attributes and properties that are new for Struts 1.4:
  
     * "component" attribute identifies an action as a component manager, such 
actions are processed differently by Action class. This name is also used in 
generated HTML for in-place update in Ajax mode.
     * "view" attribute identifies a default view for a component. Must be a 
JSP page. Often consists from several subviews, in our case the Login Component 
has two subviews "Not Logged In" and "Logged In", they will be defined in JSP 
file.
     * "form" is just another name for "name" property
-    * "event" property allows to define request parameters as events, and 
corresponding method handlers. That is right, dispatching functions are now 
supported in the core Struts, by Action class.
+    * "event" property allows to define request parameters as events, and 
corresponding method handlers. This is made possible by supporting dispatching 
functionality directly in Action class.
  
  == Component Action ==
  
@@ -261, +274 @@

  
  This is pretty much it. Now run the application and navigate to composite 
page. The included component will evaluate user's state and will display a 
login form. Try to log in. The submitted credentials are sent directly to a 
component, if they are not correct, the composite page is redisplayed. How? 
Behind the scenes the improved Action class as well as JSP tags work together 
to distinguish the address of a composite page during first render. This 
address is saved automatically. Then after component finishes, it reloads the 
composite page using saved address. Now you can develop independent Struts 
components!
  
+ 
+ = Building An Asynchronous Component with Struts 1.4 =
+ 
  Next installment: making components that update themselves in place without 
full page reload (Ajax mode).
  
  == Download ==

Reply via email to