struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [10/13] struts-site git commit: Migrates Getting started guide from Confluence to MD
Date Fri, 31 Mar 2017 05:48:12 GMT
http://git-wip-us.apache.org/repos/asf/struts-site/blob/39272be0/source/getting-started/processing-forms.md
----------------------------------------------------------------------
diff --git a/source/getting-started/processing-forms.md b/source/getting-started/processing-forms.md
new file mode 100644
index 0000000..585f29e
--- /dev/null
+++ b/source/getting-started/processing-forms.md
@@ -0,0 +1,270 @@
+---
+layout: default
+title: Processing forms
+---
+## Processing Forms
+
+This tutorial assumes you've completed the _Coding Struts 2 Actons_  tutorial and have a working coding_actions project. The example code for this tutorial, form_processing, is available for checkout from the Struts 2 GitHub subversion repository: [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples).
+
+> 
+
+__Introduction__
+
+In this tutorial we'll explore using Struts 2 to do more involved processing of a form submission. We'll cover how to use a Java model class to store the form input and how to create the Struts 2 form to match up with that model class.
+
+The code provided in this tutorial may be added to the _Coding Struts 2 Actions_  example or you can download this complete example from Google Code - [http://code.google.com/p/struts2-examples/downloads/list](http://code.google.com/p/struts2-examples/downloads/list).
+
+
+
+| The [Struts 2 user mailing list](http://struts.apache.org/mail.html)^[http://struts.apache.org/mail.html] is an excellent place to get help. If you are having a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don't find an answer to your problem, post a question on the mailing list.
+
+| 
+
+__Forms and A Java Model Class__
+
+For this tutorial let's say we need to provide a form that a user may submit to register for a prize drawing. Our business rules state the user must provide his/her first name, last name, email address, and age.
+
+To encapsulate this data, we'll use a simple Java class that follows the basic Java Bean specifications (public set/get methods for each instance field). If you're following along add this class to package org.apache.struts.register.model in the _Coding Struts 2 Actions_  example.
+
+**Person.java**
+
+
+~~~~~~~
+public class Person
+{
+    private String firstName;
+    private String lastName;
+    private String email;
+    private int age;
+
+    public String getFirstName()
+    {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName)
+    {
+        this.firstName = firstName;
+    }
+
+    public String getLastName()
+    {
+        return lastName;
+    }
+
+    public void setLastName(String lastName)
+    {
+        this.lastName = lastName;
+    }
+
+    public String getEmail()
+    {
+        return email;
+    }
+
+    public void setEmail(String email)
+    {
+        this.email = email;
+    }
+
+    public int getAge()
+    {
+        return age;
+    }
+
+    public void setAge( int age)
+    {
+        this.age = age;
+    }
+
+
+    public String toString()
+    {
+        return "First Name: " + getFirstName() + " Last Name:  " + getLastName() + 
+        " Email:      " + getEmail() + " Age:      " + getAge() ;
+    }
+}
+
+~~~~~~~
+
+Note a few points about the above class. There is a public set/get method for each instance field. The age attribute is of type integer. We've defined a public toString method that returns a String representing the state of the object. Since we haven't specified a constructor, Java will provide a default constructor that will set all instance fields to their null values.
+
+__Form Structure__
+
+To collect the above information we'll use a Struts 2 form. When creating this form the key concept we need to employ is to tie each form field to a specific instance field of an object of type Person. Let's look over the form first and then discuss some key points. Create a view page named register.jsp (in WebContent (Ant version) or src/main/webapp (Maven version) )
+
+**register.jsp**
+
+
+~~~~~~~
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+    pageEncoding="ISO-8859-1"%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<title>Register</title>
+</head>
+<body>
+<h3>Register for a prize by completing this form.</h3>
+
+<s:form action="register">
+
+ 	  <s:textfield name="personBean.firstName" label="First name" />
+ 	  <s:textfield  name="personBean.lastName" label="Last name" />
+ 	  <s:textfield name="personBean.email"  label ="Email"/>  
+ 	  <s:textfield name="personBean.age"  label="Age"  />
+ 	  
+   	  <s:submit/>
+   	  
+</s:form>	
+ 
+</body>
+</html>
+
+~~~~~~~
+
+Since we are using Struts 2 tags, at the top of the page we need the Struts tag library declaration.
+
+The Struts 2 form will submit to an action named register. We'll need to define that action in our struts.xml file.
+
+Note the four Struts 2 textfield tags. Each tag has a name value that includes an attribute of the Person class (e.g. firstName). The name attribute's value also has a reference to an object called personBean. This object is of type Person. When we create the Action class that handles this form submission, we'll have to specify that object in that Action class (see below).
+
+The complete name value, personBean.firstName, instructs Struts 2 to use the input value for that textfield as the argument to the personBean object's setFirstName method. So if the user types "Bruce" in the textfield that has the label "First name", the personBean's firstName instance field will have a value of "Bruce".
+
+Note we have a Struts 2 textfield for each instance field of the class Person. Remember that Person class's age attribute is of type integer. All form field input values are Strings. Struts 2 will automatically convert the String value ("25") the user entered for the age form field to 25 when calling the setAge method of object personBean.
+
+__Creating the Action Class To Handle the Form Submission__
+
+When the user clicks on the submit button of the above form, the action "register" and the form data will be sent to the Struts 2 framework. We need an Action class to process this form. If you recall from the tutorial _Coding Struts 2 Actions_  our Action class should extends the Struts 2 ActionSupport class.
+
+Here is the Action class used for this example. Place it in package org.apache.struts.register.action.
+
+**Register.java Struts 2 Action Class**
+
+
+~~~~~~~
+package org.apache.struts.register.action;
+
+import org.apache.struts.register.model.Person;
+
+import com.opensymphony.xwork2.ActionSupport;
+
+public class Register extends ActionSupport {
+	
+	private static final long serialVersionUID = 1L;
+	
+	private Person personBean;
+	
+
+	@Override
+	public String execute() throws Exception {
+		
+		//call Service class to store personBean's state in database
+		
+		return SUCCESS;
+		
+	}
+	
+	public Person getPersonBean() {
+		
+		return personBean;
+		
+	}
+	
+	public void setPersonBean(Person person) {
+		
+		personBean = person;
+		
+	}
+
+}
+
+~~~~~~~
+
+In the Register class note that we've declared an attribute named personBean of type Person and there is a public get and set method for this object.
+
+The Register class also overrides the execute method. The execute method is the one we will specify in the struts.xml to be called in response to the register action. In this example, the execute method just returns the String constant SUCCESS (inherited from ActionSupport class). But in a real application, within the execute method we would call upon other classes (Service objects) to perform the business processing of the form, such as storing the user's input into a data repository.
+
+The personBean object of type Person declared in the Register Action class matches the personBean name we used in the form's textfields. When the form is submitted, the Struts 2 framework will inspect the Action class and look for an object named personBean. It will create that object using the Person class's default constructor. Then for each form field that has a name value of personBean.someAttribute (e.g personBean.firstName) it will call the personBean's public set method for that attribute and pass it the form field's value (the user input). This all happens before the execute method occurs.
+
+When Struts 2 runs the execute method of class Register, the personBean object in class Register now has values for its instance fields that are equal to the values the user entered into the corresponding form fields.
+
+By using a Java model class to encapsulate the data provided by the form we don't have to have a separate attribute (with public set/get methods) in the Action class (Register) for each form field.
+
+__Handle SUCCESS Being Returned By Execute Method__
+
+When SUCCESS is returned by the execute method we want to display a simple thank you page that shows the user's registration. Add the thankyou.jsp below to either WebContent (Ant) or src/main/webapp (Maven).
+
+**thankyou.jsp**
+
+
+~~~~~~~
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+    pageEncoding="ISO-8859-1"%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<title>Registration Successful</title>
+</head>
+<body>
+<h3>Thank you for registering for a prize.</h3>
+
+<p>Your registration information: <s:property value="personBean" /> </p>
+
+<p><a href="<s:url action='index' />" >Return to home page</a>.</p>
+
+</body>
+</html>
+
+
+
+~~~~~~~
+
+If you don't recall how the Struts 2 property and url tags work consult the [Using Struts 2 Tags](#PAGE_14811875) tutorial.
+
+__Create action Node In struts.xml__
+
+To specify the relationship between the form submission page, the Struts 2 Action class, and the success view page we need to add an action node to struts.xml. Add this action node to struts.xml (src folder (Ant version) or src/main/resources (Maven version) ) after the hello action and before the closing package node.
+
+**action node for struts.xml**
+
+
+~~~~~~~
+<action name="register" class="org.apache.struts.register.action.Register" method="execute">
+  <result name="success">/thankyou.jsp</result>
+</action>
+
+
+~~~~~~~
+
+The above action tells Struts 2 that when the register action is provided to call method execute of class Register. If that method returns result "success" return to the browser the thankyou.jsp.
+
+Note that we don't need to tell Struts 2 anything about processing the form. The transfer of the form field input values to the personBean object will happen automatically provided we've followed the convention of naming our form fields to match personBean.attributeName (e.g. personBean.lastName).
+
+__Create A Link To register.jsp__
+
+So that the user can find the registration page, add this link to index.jsp
+
+**Link to register.jsp**
+
+
+~~~~~~~
+<p><a href="register.jsp">Please register</a> for our prize drawing.</p>
+
+~~~~~~~
+
+__Run The Example__
+
+If everything is correct, you should be able to create the war file, deploy the war file to your Servlet container, and open this URL in your web browser: [http://localhost:8080/form_processing/index.action](http://localhost:8080/form_processing/index.action). On that page should be a link to register. Click on that link and you should see the register.jsp page.
+
+![registerjsp.png](attachments/att14974999_registerjsp.png)
+
+Fill out the form and click the submit button. You should then see the thankyou.jsp page.
+
+![thanyoujsp.png](attachments/att14975000_thanyoujsp.png)

http://git-wip-us.apache.org/repos/asf/struts-site/blob/39272be0/source/getting-started/spring.md
----------------------------------------------------------------------
diff --git a/source/getting-started/spring.md b/source/getting-started/spring.md
new file mode 100644
index 0000000..0153349
--- /dev/null
+++ b/source/getting-started/spring.md
@@ -0,0 +1,224 @@
+---
+layout: default
+title: Spring
+---
+## Spring and Struts 2
+
+The example code for this tutorial, spring_struts, is available for checkout at [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples)
+
+> 
+
+#####Introduction#####
+
+In the execute method of many Struts 2 ActionSupport classes are statements that create objects and then have those objects execute methods that perform needed tasks. Whenever one class creates an object of another class that introduces a dependency between the two classes. The Spring framework makes it easier for the application developer to manage these dependencies and helps make the application more flexible and maintainable. This tutorial will show you how to use Struts 2 and Spring together to manage the dependencies between your ActionSupport classes and other classes in your application.
+
+
+> 
+
+> 
+
+> This tutorial assumes you understand how to use the Spring framework to manage dependencies between classes. You can learn more about Spring by reading the documentation at [http://www.springsource.org/documentation](http://www.springsource.org/documentation)
+
+> 
+
+
+| 
+
+| The [Struts 2 user mailing list](http://struts.apache.org/mail.html)^[http://struts.apache.org/mail.html] is an excellent place to get help. If you are having a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don't find an answer to your problem, post a question on the mailing list.
+
+| 
+
+If you examine the example application for the [Struts 2 Themes](#PAGE_23337450) tutorial you'll see this code in the EditAction ActionSupport class
+
+**EditAction Class Hard-Coded Dependency**
+
+
+~~~~~~~
+private EditService editService = new EditServiceInMemory();
+
+
+~~~~~~~
+
+The above statement hard-codes a dependency between the EditAction class and the EditServiceInMemory class. This is poor design for two reasons.
+
+1. If I need to replace the EditServiceInMemory with another class that implements the EditService interface I'll have to hunt down and replace all statements where I hard-coded the dependency.
+
+2. I cannot test EditAction without using the EditServiceInMemory class. I cannot isolate EditAction by using a stub implementation of EditService when writing my test case because the use of EditServiceInMemory is hard-coded.
+
+Spring provides a mechanism to manage dependencies by injecting them at run time. Struts 2 ActionSupport classes—like any other Java class—can be injected with a dependent object by the Spring framework. So instead of having the above code, I would have this statement in EditAction.
+
+**EditAction Class No Hard-Coded Dependency**
+
+
+~~~~~~~
+    private EditService editService ;
+
+
+~~~~~~~
+
+At run time the Spring framework will provide an object of a class that implements the EditService interface.
+
+#####Struts 2 Spring Plugin#####
+
+Struts 2 provides a plugin that enables Spring to inject into the ActionSupport classes any dependent objects you've specified in the Spring configuration file. Consult _Spring Plugin documentation_  for more information about how the plugin works.
+
+For a Maven application you'll need to add a dependency to the struts2-spring-plugin jar (see the Maven example application for this tutorial). The plugin's pom.xml includes transitive dependencies to the Spring jar files.
+
+
+
+| The current version (2.3.15) of the Struts 2 Spring plugin has transitive dependencies to the Spring 3.0.5 version. If you want to use the latest version of Spring, then you should exclude the transitive dependencies in your pom.xml for the Struts 2 Spring plugin and then declare dependency nodes to the current version of the Spring jar files. If you are using Ant and explicitly including the jar files in your application, then just include the latest version of the Spring jar files.
+
+| 
+
+In your ActionSupport class you must have a set method for the dependent object that follows standard Java bean naming conventions. If you examine the EditAction class for this tutorial's application you'll see this set method.
+
+
+~~~~~~~
+public void setEditService(EditService editService) {
+		
+   this.editService = editService;
+		
+}
+
+
+~~~~~~~
+
+Spring will use that set method to provide an object of type EditService to the EditAction class at run time.
+
+To make our application "Spring aware" we need to add this line to web.xml.
+
+**Spring Listener In web.xml**
+
+
+~~~~~~~
+<listener>
+	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+</listener>
+
+
+~~~~~~~
+
+The above code will activate the Spring framework when the application is started up by the Servlet container. By default Spring will look for a configuration file name applicationContext.xml in WEB-INF (consult the Spring documentation for how you can change where Spring looks and what the configuration file name is).
+
+#####Spring Configuration File#####
+
+In the Spring configuration file we create a bean node for those objects we want Spring to create an instance of and inject into our ActionSupport class. In the example application is this applicationContext.xml.
+
+**Spring Configuration File**
+
+
+~~~~~~~
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+            http://www.springframework.org/schema/beans
+            http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+<bean id="editService" class="org.apache.struts.edit.service.EditServiceInMemory" />
+
+</beans>
+
+
+~~~~~~~
+
+Note the id value above. By default the Spring plugin works with Spring to autowire the dependencies of the ActionClass by "name." Spring will create an object of class EditServiceMemory and provide that object to any ActionSupport class that has a setEditService method with an argument of type EditService. Consult the _Spring Plugin_  documentation for how to change the default autowire method.
+
+
+
+| The editService bean created by Spring will have a scope of singleton since that is the default scope. Consult section 3.5 of the [Spring documentation](http://www.springsource.org/documentation)^[http://www.springsource.org/documentation] for how to configure the bean definition to use a different scope (e.g. request or session).
+
+| 
+
+#####Alternative - Have Spring Manage Creation Of ActionSupport Class#####
+
+Using the above methodology, the Struts 2 framework will still manage the creation of the ActionSupport class. If you prefer you can configure the application so that Spring will create the ActionSupport class also. To support this technique you need to add a bean node to the Spring configuration file for the ActionSupport class.
+
+**Spring Configuration For ActionSupport Class Managed By Spring**
+
+
+~~~~~~~
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+            http://www.springframework.org/schema/beans
+            http://www.springframework.org/schema/beans/spring-beans.xsd">
+            
+
+<bean id="editService" class="org.apache.struts.edit.service.EditServiceInMemory" />
+
+<bean id="editAction" class="org.apache.struts.edit.action.EditAction" scope="prototype">
+
+	<property name="editService" ref="editService" />
+	
+</bean>
+
+</beans>
+
+
+~~~~~~~
+
+Note in the above that there is an 
+
+~~~~~~~
+editAction
+~~~~~~~
+ bean and its 
+
+~~~~~~~
+editService
+~~~~~~~
+ property is set to the 
+
+~~~~~~~
+editService
+~~~~~~~
+ bean. Since we are having Spring manage the 
+
+~~~~~~~
+EditAction
+~~~~~~~
+ class we must specify any properties of 
+
+~~~~~~~
+EditAction
+~~~~~~~
+ that we want Spring to inject. Please remember that actions must be created on each request, they cannot be 
+
+~~~~~~~
+singletons
+~~~~~~~
+ - this is the default 
+
+~~~~~~~
+scope
+~~~~~~~
+ that's why it must be changed to 
+
+~~~~~~~
+prototype
+~~~~~~~
+.
+
+In the 
+
+~~~~~~~
+struts.xml
+~~~~~~~
+ configuration file you must specify the Spring id value for the class attribute of the action node. This tells Struts to get a bean with that id value from Spring for the Action class.
+
+**Struts Configuration For Spring Managed ActionSupport Class**
+
+
+~~~~~~~
+<action name="edit" class="editAction" method="input">
+	<result name="input">/edit.jsp</result>
+</action>
+
+
+~~~~~~~
+
+#####Summary#####
+
+In this tutorial we reviewed how to use the Struts 2 Spring plugin to integrate Spring and Struts. By using the Struts 2 Spring plugin you can have Spring manage the dependencies of your ActionSupport classes. Of course you can also take advantage of the many other benefits (AOP, Spring JDBC) that the Spring framework provides.

http://git-wip-us.apache.org/repos/asf/struts-site/blob/39272be0/source/getting-started/themes.md
----------------------------------------------------------------------
diff --git a/source/getting-started/themes.md b/source/getting-started/themes.md
new file mode 100644
index 0000000..e15c42a
--- /dev/null
+++ b/source/getting-started/themes.md
@@ -0,0 +1,177 @@
+---
+layout: default
+title: Themes
+---
+## Themes
+
+The example code for this tutorial, themes, is available for checkout at [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples)
+
+> 
+
+#####Introduction#####
+
+When you use a Struts 2 tag such as s:select in your web page, the Struts 2 framework generates HTML that styles the appearance and controls the layout of the select control. The style and layout is determined by which Struts 2 theme is set for the tag. Struts 2 comes with three built-in themes: simple, xhtml, and css_xhtml. If you don’t specify a theme, then Struts 2 will use the xhtml theme by default.
+
+
+
+| The [Struts 2 user mailing list](http://struts.apache.org/mail.html)^[http://struts.apache.org/mail.html] is an excellent place to get help. If you are having a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don't find an answer to your problem, post a question on the mailing list.
+
+| 
+
+For example, this Struts 2 select tag:
+
+**Struts 2 Select Tag**
+
+
+~~~~~~~
+<s:select key="personBean.sport" list="sports" />
+
+~~~~~~~
+
+generates this HTML markup:
+
+**HTML Created By Struts 2 Select Tag**
+
+
+~~~~~~~
+<tr>
+<td class="tdLabel">
+<label for="save_personBean_sport" class="label">Favorite sport:</label>
+</td>
+<td>
+<select name="personBean.sport" id="save_personBean_sport">
+    <option value="football">football</option>
+    <option value="baseball">baseball</option>
+    <option value="basketball" selected="selected">basketball</option>
+</select>
+</td>
+</tr>
+
+~~~~~~~
+
+Notice how the HTML generated uses table tags to control the layout of the label and select HTML. There is also a class, tdLabel, applied to the table column where the label tag is rendered. Since no theme was specified for the Struts 2 select tag the default xhmtl theme was used.
+
+#####Specifying The Theme Struts 2 Should Use#####
+
+The Struts 2 tags have a theme attribute you can use to specify which Struts 2 theme should be used when creating the HTML for that tag. The values for the theme attribute are simple, xhtml, css_xhtml, and ajax. To learn more about these themes visit _Themes and Templates Documentation_ . This tutorial will review the xhtml, css_xhtml, and the simple themes. The ajax theme is a special theme used for ajax operations (see _Ajax Theme in the documentation_ ).
+
+You can specify the theme on a per Struts 2 tag basis or you can use one of the following methods to specify what theme Struts 2 should use:
+
+1. The theme attribute on the specific tag
+
+2. The theme attribute on a tag's surrounding form tag
+
+3. The page-scoped attribute named "theme"
+
+4. The request-scoped attribute named "theme"
+
+5. The session-scoped attribute named "theme"
+
+6. The application-scoped attribute named "theme"
+
+7. The struts.ui.theme property in struts.properties (defaults to xhtml)
+
+Consult _Selecting Themes_  for how to set the theme using the above approaches.
+
+In the example application, examine edit.jsp. The theme attribute of the form tag is set to xhtml. Run the application (see the readme.txt file) and view the source for edit.jsp after it is rendered in your browser. You should see the form HTML tags layout controlled by table tags.
+
+Change the theme to simple for the form’s theme attribute and redeploy the application. Examine the source for edit.jsp after it is rendered in the browser. You should see that there are no table tags controlling the layout and also there are no label tags for the text fields.
+
+Change the theme to css_xhtml for the form’s theme attribute and redeploy the application. Examine the source for edit.jsp after it is rendered in the browser. The layout of the form tags is now controlled by div tags and the label tags are back.
+
+#####Specifying The CSS Used By The Struts 2 Tag#####
+
+Change the theme attribute for the form tag back to xhtml. Notice when you view the source of edit.jsp after it is rendered in the browser that there is a class named tdLabel applied to the table column that contains the label. This CSS class controls the position of the label in the table column. The tdLabel style is defined in /themes/struts/xhtml/styles.css. The link to this style sheet was included in edit.jsp’s head section when you add the s:head tag to edit.jsp.
+
+Load this style sheet in your browser (in the example application the link is [http://localhost:8080/themes/struts/xhtml/styles.css](http://localhost:8080/themes/struts/xhtml/styles.css) if your Servlet container is running on localhost, port 8080). You’ll see the following:
+
+**styles.css**
+
+
+~~~~~~~
+.label {font-style:italic; }
+.errorLabel {font-style:italic; color:red; }
+.errorMessage {font-weight:bold; color:red; }
+.checkboxLabel {}
+.checkboxErrorLabel {color:red; }
+.required {color:red;}
+.tdLabel {text-align:right; vertical-align:top; }
+
+~~~~~~~
+
+So the .label selector renders the label tag’s text in italic. The .tdLabel tag specifies that the text should align to the right and top of the table column.
+
+You can override the above selectors by including the same selectors in your page’s head section. For example add the following to the head section of edit.jsp.
+
+**Override Label Style**
+
+
+~~~~~~~
+<style type="text/css">
+  .label {color:blue; font-style:normal; font-weight:bold}
+</style>
+
+~~~~~~~
+
+Now the label tag will render the text in blue, bold, normal (not italics) style.
+
+#####Creating And Applying Your Own Themes For Struts 2 Tags#####
+
+The theme templates (simple, xhtml, css_xhtml) can be found in the Struts 2 core jar file. If you expand (extract the files) the Struts 2 core jar file you'll find folders named template.css_xhtml, template.simple, and template.xhtml. Those folders contain the templates for the three default Struts 2 themes. In each folder is a file for each Struts 2 tag. For example if you expand the template.xhtml folder you’ll see the select.ftl file.
+
+The Struts 2 framework uses the FreeMarker template engine to generate the HTML for the Struts 2 tags. That's why the file extension is ".ftl". You can learn more about FreeMarker by visiting [http://freemarker.sourceforge.net/](http://freemarker.sourceforge.net/).
+
+Also in the template.xhmtl folder is the styles.css file. This is the styles.css file that your application will use if it uses the xhtml theme.
+
+Let’s say we wanted to create our own theme that will change how the Struts 2 checkboxlist tag displays the checkboxes and their labels.
+
+In the example application I've extended the default XHMTL theme (see file theme.properties under src/main/resources/template/KUTheme).  The checkboxlist.ftl theme that is part of the XHTML theme only includes a space between each label and the next checkbox (see checkboxlist.ftl in the template/simple folder in Struts 2 core). That is why all the checkboxes are displayed across the width of the browser window. For my custom checkboxlist theme I want to have a break tag after each label tag so that each checkbox and its label will be on their own line.
+
+In the example application there is a folder named src/main/resources/template/KUTheme. In that folder is a checkboxlist.ftl, the contents of which I originally copied from the checkboxlist.ftl that is in the templates.xhtml folder from the struts 2 core jar.
+
+I then modified the checkboxlist.ftl in the KUTheme folder to be:
+
+**Modified checkboxlist.ftl**
+
+
+~~~~~~~
+<#include "/${parameters.templateDir}/${parameters.expandTheme}/controlheader.ftl" />
+
+<#include "/${parameters.templateDir}/KUTheme_simple/checkboxlist.ftl" />
+
+<#include "/${parameters.templateDir}/${parameters.expandTheme}/controlfooter.ftl" /><#nt/>
+
+~~~~~~~
+
+Be sure to note the change to the second line—using KUTheme_simple in the path.
+
+Then in the example application I created a KUTheme_simple folder under 
+
+~~~~~~~
+src/main/resources/template
+~~~~~~~
+ (optionally you can place it under 
+
+~~~~~~~
+webapp
+~~~~~~~
+, e.g. 
+
+~~~~~~~
+src/main/webapp/template
+~~~~~~~
+). In that folder I created checkboxlist.ftl and copied the contents from template.simple checkboxlist.ftl (again found in the Struts 2 core jar). After copying the contents to checkboxlist.ftl that is in KUTheme_simple folder, I modified checkboxlist.ftl so that the label tag has a style of red bold text and I added a break tag after each label so that each check box and label will be on its own line.
+
+Since the XHTML theme is the default theme and I have a theme.properties file defined with parent = xhtml, the KUTheme will inherit all the themes from xhmtl exempt for the theme for the checkboxlist tag since my KUTheme includes a definition for that tag's layout.  In the struts.xml file (src/main/resources) you will see that the I've specified the default theme to be KUTheme.
+
+In the deployed web application, Struts 2 will first look for a tag's template on the application's class path and if it doesn't find the template there it will use the default template that is part of the Struts 2 core jar. Since we've added a template folder to the application's web root, now when Struts 2 creates the HTML to display the checkboxlist tag it will use the template that is in the KUTheme folder (which tells it to use the checkboxlist.ftl file that is in the KUTheme_simple folder instead of the one in the template.simple folder that is part of the Struts 2 core Jar).
+
+After redeploying the application the check boxes for the Car Models Owned should appear like:
+
+![Screen shot 2010-09-11 at 12.37.12 PM.png](attachments/att23527657_Screen shot 2010-09-11 at 12.37.12 PM.png)
+
+#####Summary#####
+
+You can easily override the default theme used by Struts 2 to control the appearance and layout of a Struts 2 tag. Each Struts 2 tag has an associated template file (e.g. select.ftl) that is in a folder named after the theme (e.g. xhtml). By default the Struts framework will look in the Struts 2 core Jar file for the theme folder and templates. However, if you include your own theme folder (e.g. KUTheme) under webapp/template (or WebContent/template in the Ant version) and specify that folder name (e.g. KUTheme) as the value for the theme attribute, then the Struts 2 framework will look in that theme folder for the tag's template.
+
+To learn more about how to use the Struts 2 themes and how you can override them, visit _Themes and Templates Documentation_ .

http://git-wip-us.apache.org/repos/asf/struts-site/blob/39272be0/source/getting-started/unit-testing.md
----------------------------------------------------------------------
diff --git a/source/getting-started/unit-testing.md b/source/getting-started/unit-testing.md
new file mode 100644
index 0000000..8fbf911
--- /dev/null
+++ b/source/getting-started/unit-testing.md
@@ -0,0 +1,144 @@
+---
+layout: default
+title: Unit testing
+---
+## Unit Testing
+
+The example code for this tutorial, unit_testing, is available at [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples)
+
+> 
+
+#####Introduction#####
+
+Struts 2 supports running unit tests of methods in the Struts Action class with the [Struts 2 JUnit plugin](http://struts.apache.org/2.3.1.2/docs/junit-plugin.html)^[http://struts.apache.org/2.3.1.2/docs/junit-plugin.html]. The JUnit plugin allows you to test methods of an Action class from within the Struts 2 framework. The Struts Servlet filter and interceptors fire just as if your application was running on a Servlet container.
+
+
+
+| The [Struts 2 user mailing list](http://struts.apache.org/mail.html)^[http://struts.apache.org/mail.html] is an excellent place to get help. If you are having a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don't find an answer to your problem, post a question on the mailing list.
+
+| 
+
+#####Setup#####
+
+The Struts 2 JUnit plugin jar file must be on your application's class path. In the example application (see info above) the pom.xml includes a dependency for the struts2-junit-plugin. There are numerous transitive dependencies, including to JUnit and the Spring framework.
+
+#####Writing A Unit Test#####
+
+In the example application, the Register Action class includes using the validate method. This method is automatically executed by the Struts 2 framework prior to the execute method. Additionally, this method needs the values from the user's input on the form to already have been provided to the instance fields of the Action class (this work is done by another Struts 2 interceptor). So it would be difficult to test the validate method without the overall Struts 2 framework running.
+
+To use the Struts 2 plugin to ensure the Strut 2 framework runs as part of the test, you need to have your JUnit test class extend StrutsTestCase (see RegisterTest class in the example application).
+
+
+> 
+
+> 
+
+> Note that the Struts 2 JUnit plugin can be used to design unit tests of other Action class methods such as the input method and also to test methods of a custom interceptor you add to the interceptor stack. Also in this example, the test is for validation performed in the _validate method_ . But the same type of test would work if the validation was done using [XML file validation](#PAGE_20644608).
+
+> 
+
+To test the validate method we want Struts to call the Struts action that will cause the Action class's validate and execute methods to be run. In the example application this action is register.
+
+**struts.xml**
+
+
+~~~~~~~
+	  <action name="register" class="org.apache.struts.register.action.Register" method="execute">
+		<result name="success">/thankyou.jsp</result>
+		<result name="input">/register.jsp</result>
+	  </action>
+
+
+~~~~~~~
+
+Remember the validate method will be called automatically by the framework before calling the execute method. If validation fails the Struts framework will return "input". If there are no validation errors then the framework will call the execute method and return whatever String the execute method returns.
+
+#####Test Validation Should Pass#####
+
+For our first test we'll test that there should be no validation errors. In the normal flow of this application the user would first enter the form data shown on the register.jsp page.
+
+![Screen shot 2012-02-17 at 2.46.54 PM.png](attachments/att28017281_Screen shot 2012-02-17 at 2.46.54 PM.png)
+
+The input fields for the form have the following name values: personBean.firstName, personBean.lastName, personBean.email, and personBean.age. When the user fills out those fields Struts will take the values and provide them to the appropriate set methods of the personBean object. So as part of the test I need to simulate the user filling out these form fields. The StrutsTestCase provides a request object (of type MockHttpServletRequest) that I can use to set these values in the request scope.
+
+**testExecuteValidationPasses method from RegisterTest class**
+
+
+~~~~~~~
+@Test
+public void testExecuteValidationPasses() throws Exception() {
+
+  request.setParameter("personBean.firstName", "Bruce");
+
+  request.setParameter("personBean.lastName", "Phillips");
+		
+  request.setParameter("personBean.email", "bphillips@ku.edu");
+		
+  request.setParameter("personBean.age", "19");
+
+  ActionProxy actionProxy = getActionProxy("/register.action");
+
+  Register action = (Register) actionProxy.getAction() ;
+
+  assertNotNull("The action is null but should not be.", action);
+
+  String result - actionProxy.execute();
+
+  assertEquals("The execute method did not return " + ActionSupport.SUCCESS + " but should have.", ActionSupport.SUCCESS, result);
+  
+}
+
+
+~~~~~~~
+
+The first statements in the test method use the request object to set the values of any request parameters. These simulate the values the user would enter into the form fields. Note how the first argument to setParameter is the same as the value of the name attribute in the Struts textfield tag in the register.jsp page.
+
+In this test I'm providing good data for each form field as I want to ensure my validation doesn't register an error if the user provides correct information.
+
+I then call the getActionProxy method with the argument of "/register.action" and then the getAction method to get a reference to the Struts action class for this test. This will ensure that the Struts 2 JUnit plugin will know which Action class should be used--the class associated with the register action in the struts.xml. In this case that class is the Register class.
+
+The assertNotNull test ensures that argument to getActionProxy reference an Action class identified in struts.xml. It's a way of checking that you've correctly setup struts.xml for this action.
+
+After that I can call actionProxy.execute(). This causes the Struts 2 framework to go through its normal process of Servlet fileter and interceptors for the action identified by the actionProxy (in this case that is the register.action). The validate method of class Register will get called and if it doesn't create any field or action errors then Struts 2 will call the execute method. In this example, the execute method should return "success".
+
+So in the next statement, I check that success was returned.
+
+#####Test Validation Should Fail#####
+
+To test that validation should fail, I just need to have a test method that doesn't provide input for a form field. For example, in the validate method of the Register Action class, is a test to ensure the user has entered some information for the personBean.firstName input field. In the test method I would just not use the request object to set a parameter for that field.
+
+**testExecuteValidationFailsMissingFirstName method from RegisterTest class**
+
+
+~~~~~~~
+@Test
+public void testExecuteValidationFailsMissingFirstName() throws Exception() {
+
+  //request.setParameter("personBean.firstName", "Bruce");
+
+  request.setParameter("personBean.lastName", "Phillips");
+		
+  request.setParameter("personBean.email", "bphillips@ku.edu");
+		
+  request.setParameter("personBean.age", "19");
+
+  ActionProxy actionProxy = getActionProxy("/register.action");
+
+  Register action = (Register) actionProxy.getAction() ;
+
+  assertNotNull("The action is null but should not be.", action);
+
+  String result - actionProxy.execute();
+
+  assertEquals("The execute method did not return " + ActionSupport.INPUT + " but should have.", ActionSupport.INPUT, result);
+  
+}
+
+
+~~~~~~~
+
+In the last assertEquals statement my test checks that the Struts 2 framework returned "input" as that is what the Struts 2 framework will return if the validation adds a field or action error.
+
+#####Summary#####
+
+There is much more you can do with the Struts 2 JUnit plugin to help you test the methods of your Action class in conjunction with the Struts 2 fraemwork. If your Struts 2 application uses Spring to inject dependencies into the Action class then the Struts 2 JUnit Plugin has a StrutsSpringTestCase that your test class should extend. Please read [Testing Actions](http://struts.apache.org/2.3.1.2/docs/testing-actions.html)^[http://struts.apache.org/2.3.1.2/docs/testing-actions.html] to learn more.

http://git-wip-us.apache.org/repos/asf/struts-site/blob/39272be0/source/getting-started/using-tags.md
----------------------------------------------------------------------
diff --git a/source/getting-started/using-tags.md b/source/getting-started/using-tags.md
new file mode 100644
index 0000000..a3acec1
--- /dev/null
+++ b/source/getting-started/using-tags.md
@@ -0,0 +1,276 @@
+---
+layout: default
+title: Using tags
+---
+## Using Tags
+
+This tutorial assumes you've completed the [Hello World](#PAGE_14811871) tutorial and have a working helloworld project. The example code for this tutorial, using_tags, is available for checkout from the Struts 2 GitHub repository at [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples). The example projects use Maven to manage the artifact dependencies and to build the .war files.
+
+> 
+
+In the [Hello World](#PAGE_14811871) lesson, we added to the index.jsp a Struts 2 url tag to create a hyperlink to the hello.action. This tutorial will explore the url and other Struts 2 tags further.
+
+Web applications differ from conventional websites in that web applications can create a dynamic response. To make it easier to reference dynamic data from a page, the Struts 2 framework offers a set of tags. Some of the tags mimic standard HTML tag while providing added value. Other tags create non-standard, but useful controls.
+
+
+> 
+
+> 
+
+> To use the Struts 2 tags on the view page, you must include a tag library directive. Typically, the taglib directive is \<%@ taglib prefix="s" uri="/struts-tags" %\>. So the prefix for all the Struts 2 tags will be "s". 
+
+>  If you want to actually read the Struts 2 tag TLD file, you'll find it in the META-INF folder of the Struts 2 core jar.
+
+> 
+
+__Struts 2 url Tag__
+
+One use of the Struts 2 Tags is to create links to other web resources, especially to other resources in the local application.
+
+
+
+| While HTML provides a simple a tag for creating hyperlinks, the HTML tag often requires us to include redundant information. Also the HTML tag cannot easily access dynamic data provided by the framework.
+
+| 
+
+A very common use case in web applications is linking to other pages. In the _Hello World_  tutorial we added to index.jsp a link to the hello.action using the Struts 2 url tag. Please refer to the _url documentation_  for more information about the url tag.
+
+**index.jsp**
+
+
+~~~~~~~
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+    pageEncoding="ISO-8859-1"%>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Basic Struts 2 Application - Welcome</title>
+</head>
+<body>
+<h1>Welcome To Struts 2!</h1>
+<p><a href="<s:url action='hello'/>">Hello World</a></p>
+</body>
+</html>
+
+~~~~~~~
+
+When you run the Hello World tutorial in your Servlet container and then mouse over the Hello World hyperlink created by the Struts 2 url tag you'll see that the URL created is hello.action (relative to the web context's root folder).
+
+Examine the struts.xml configuration in the Hello World tutorial and you will find this:
+
+**struts.xml**
+
+
+~~~~~~~
+...
+<action name="hello" class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute">
+  <result name="success">/HelloWorld.jsp</result>
+</action>
+...
+
+~~~~~~~
+
+The action node above maps the hello.action to the execute method of class HelloWorldAction. If the execute method returns success, the view page HelloWorld.jsp (in web context root folder) will be returned to the user.
+
+A common use case is that the URL also needs to include a value for a query string parameter such as userName. To add a query string parameter and its value use the Struts 2 param tag, nested inside the url tag.
+
+For the Using Tags tutorial add the following to index.jsp just after the link for Hello World.
+
+**url tag with param**
+
+
+~~~~~~~
+<s:url action="hello" var="helloLink">
+  <s:param name="userName">Bruce Phillips</s:param>
+</s:url>
+
+<p><a href="${helloLink}">Hello Bruce Phillips</a></p>
+
+
+~~~~~~~
+
+Rather then put the url tag as the value for the anchor tag's href attribute, we've separated out the s:url tag into its own code block. Nested inside the url tag is the Struts 2 param tag. This tag lets you specify a parameter name (e.g. userName) and a value for that paramter (e.g. Bruce Phillips).
+
+Notice the use of the var attribute. The value of the var attribute is a reference we can use later in our code to refer to the url created.
+
+Examine the anchor tag above. Notice the value of the href attribute is \$\{helloLink\}. The view page will substitute the hyperlink we created using the url tag for the \$\{helloLink\} reference. Note that the query string parameter will be properly URL-encoded (Bruce\+Phillips).
+
+
+> 
+
+> 
+
+> In the next tutorial we'll cover how Struts can access the query string parameter value.
+
+> 
+
+__Struts 2 Form Tags__
+
+Most applications will use several data entry forms. The Struts 2 tags make creating input forms easy. Consult the _Form Tags Reference_  for all the details about the Struts 2 form tags.
+
+Each of the Struts 2 form tags has numerous attributes to mimic the normal HTML form tag attributes.
+
+To create the outer shell of the form, use the Struts 2 form tag. The action attribute sets the action name to submit to.
+
+Add the following markup to index.jsp after the Hello Bruce Phillips link.
+
+**Struts 2 Form**
+
+
+~~~~~~~
+<p>Get your own personal hello by filling out and submitting this form.</p>
+
+<s:form action="hello">
+
+  <s:textfield name="userName" label="Your name" />
+	
+   <s:submit value="Submit" />
+
+</s:form>
+
+
+
+~~~~~~~
+
+The Struts 2 _textfield_  tag provides a input html tag of tag text and the submit tag creates a submit button. When the index page is return by the server to the browser you should see:
+
+![Struts Form.png](attachments/att14974996_Struts Form.png)
+
+The Struts form, textfield, and submit tags were converted to this HTML.
+
+**Struts Form Tags Converted To HTML**
+
+
+~~~~~~~
+<form id="hello" name="hello" action="/Using_Tags_Struts2_Mvn/hello.action;jsessionid=3471d76027b5342cab44f297b567" method="post">
+
+<table class="wwFormTable">
+
+<tr>
+    <td class="tdLabel"><label for="hello_userName" class="label">Your name:</label></td>
+    <td><input type="text" name="userName" value="" id="hello_userName"/></td>
+</tr>
+
+<tr>
+    <td colspan="2"><div align="right"><input type="submit" id="hello_0" value="Submit"/>
+</div></td>
+</tr>
+
+</table>
+</form>
+
+
+
+~~~~~~~
+
+Note how Struts 2 created a table inside the form to position the form elements. In later tutorials you'll learn how to specify the layout (table, CSS). The Struts 2 textfield tag created an HTML input tag of type text with a name value that matches the name value of the textfield tag. Struts 2 also created a label HTML tag based on the label value of the textfield tag.
+
+
+> 
+
+> 
+
+> In the next tutorial we'll cover how to use Struts 2 to process this form submission.
+
+> 
+
+__Struts 2 property tag__
+
+In the [Hello World](#PAGE_14811871) tutorial's example application on JSP HelloWorld.jsp was this code:
+
+**Struts Property Tag**
+
+
+~~~~~~~
+<s:property value="messageStore.message" />
+
+
+~~~~~~~
+
+The most common use of the _property_  tag is used to "get" the value returned by calling a public get method (of the Action class) and then to include that value in the HTML returned to the browser.
+
+As discussed in the [Hello World](#PAGE_14811871) tutorial, the value of "messageStore.message" instructs Struts 2 to first call method getMessageStore of the Action class. That method call returns a MessageStore object. The ".message" part instructs Struts 2 to call the getMessage method of the MessageStore object. The getMessage method returns a String which will be included in the HTML returned to the browser.
+
+One very useful feature of the Struts 2 property tag is that it will automatically convert the most common data types (int, double, boolean) to their String equivalents. To demonstrate this feature let's add a static int variable to class HelloWorldAction.
+
+**Add Static Field**
+
+
+~~~~~~~
+private static int helloCount = 0;
+	
+public int getHelloCount() {
+	return helloCount;
+}
+
+public void setHelloCount(int helloCount) {
+	HelloWorldAction.helloCount = helloCount;
+}
+
+~~~~~~~
+
+Each time the execute method is called we'll increase helloCount by 1. So add this code to the execute method of class HelloWorldAction.
+
+**Increase helloCount**
+
+
+~~~~~~~
+helloCount++;
+
+
+~~~~~~~
+
+Whenever a user clicks one of the links on page index.jsp (or submits the form), method execute of class HelloWorldAction will be run and the static field helloCount will be increased by one.
+
+To include the value of the helloCount attribute in the HelloWorld.jsp we can use the Struts 2 property tag. Add the following to HelloWorld.jsp after the h2 tag.
+
+**Use Property Tag To Display helloCount Value**
+
+
+~~~~~~~
+<p>I've said hello <s:property value="helloCount" /> times!</p>
+
+
+~~~~~~~
+
+So even though the getHelloCount method returns an integer type, Struts 2 converted it to type String and placed it into the body of the p tag.
+
+
+
+| Note that even though helloCount is a static field, the get and set methods for helloCount are not static. For Struts 2 to call the getHelloCount method to get the value of helloCount, the getHelloCount method cannot be static.
+
+| 
+
+If the value returned by the get method is an object, then the property tag will cause Struts 2 to call the object's toString method. Of course, you should always override Class Object's toString method in your model classes. Add the following toString method to the MessageStore class:
+
+**Add toString Method To Class MessageStore**
+
+
+~~~~~~~
+public String toString() {
+		
+	return message + " (from toString)";
+		
+}	
+
+
+~~~~~~~
+
+Add the following to HelloWorld.jsp
+
+**Using Property Tag to Call toString**
+
+
+~~~~~~~
+<p><s:property value="messageStore" /></p>
+
+
+~~~~~~~
+
+Since getMessageStore of HelloWorldAction class returns a MessageStore object, Struts 2 will call the toString method of class MessageStore. The string returned by that toString method will be displayed in the browser.
+
+![displaymessagestore.png](attachments/att14974995_displaymessagestore.png)
+
+We covered a lot in this tutorial, but we've really only scratched the surface of how to use the Struts 2 tags. Consult the _Struts 2 Tag Reference_  for much more information about all the Struts 2 tags.

http://git-wip-us.apache.org/repos/asf/struts-site/blob/39272be0/source/getting-started/wildcard-method-selection.md
----------------------------------------------------------------------
diff --git a/source/getting-started/wildcard-method-selection.md b/source/getting-started/wildcard-method-selection.md
new file mode 100644
index 0000000..f0992de
--- /dev/null
+++ b/source/getting-started/wildcard-method-selection.md
@@ -0,0 +1,88 @@
+---
+layout: default
+title: Wildcard Method Selection
+---
+## Wildcard Method Selection
+
+The example code for this tutorial, wildcard_method_selection, is available for checkout at [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples)
+
+> 
+
+#####Introduction#####
+
+In this tutorial we'll cover how to configure an action node in the struts.xml configuration file so that one action node can be used to relate several different Action URLs to specific methods of the Action class. This will reduce the number of action nodes we must write in the struts.xml configuration file.
+
+
+
+| The [Struts 2 user mailing list](http://struts.apache.org/mail.html)^[http://struts.apache.org/mail.html] is an excellent place to get help. If you are having a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don't find an answer to your problem, post a question on the mailing list.
+
+| 
+
+#####Example Application#####
+
+![Screen shot 2010-05-30 at 8.51.40 AM.png](attachments/att21921805_Screen shot 2010-05-30 at 8.51.40 AM.png)
+
+The example application that supports this tutorial shows how to use Struts 2's wildcard method selection methodology. The example application is just a simple one that lists some people and lets you edit them, delete them, and add a new person to the list. Everything that the application needs to do with a Person (the model class) is controlled by the Struts 2 ActionSupport class PersonAction. The PersonAction class has several different methods (e.g. create, edit, delete) that are called depending on what the user wants to do.
+
+#####Wildcard Method Selection#####
+
+Without using the wildcard method selection technique, I'd have to write an action mapping node in the Struts 2 configuration file for each separate action I'd want to call. For example:
+
+**Struts.xml Action Configuration**
+
+
+~~~~~~~
+<action name="createPerson" class="org.apache.struts.tutorials.wildcardmethod.action.PersonAction" method="create">
+  <result name="input">input.jsp</result>
+  <result name="success">view.jsp</result>
+</action>
+
+<action name="editPerson" class="org.apache.struts.tutorials.wildcardmethod.action.PersonAction" method="edit">
+  <result name="input">input.jsp</result>
+  <result name="success">view.jsp</result>
+</action>
+
+
+~~~~~~~
+
+So even for this simple application, I'd have to write four separate action mapping nodes (create, edit, delete, saveOrUpdate) in the configuration file. So you can easily see that a more complex application can have dozens of action mapping nodes.
+
+To implement the wildcard method selection technique to enable the Struts 2 framework to dynamically select the correct method to call at runtime you just need to use the wildcard character, \*, in your name value and an attribute value place holder ( \{1\} ) for the method value. For example:
+
+**Struts.xml Action Configuration Using Wildcard Method Selection**
+
+
+~~~~~~~
+<action name="*Person" class="org.apache.struts.tutorials.wildcardmethod.action.PersonAction" method="{1}">
+  <result name="success">view.jsp</result>
+  <result name="input">input.jsp</result>
+</action>
+
+
+~~~~~~~
+
+The \* is the wildcard character. Any action name values that end in "Person" will be handled by this action mapping. Whatever value is before "Person" will be the value used for the method attribute (the \{1\} place holder will be replaced with that value). For example this URL:
+
+[http://localhost:8080/wildcard-method-selection/createPerson.action](http://localhost:8080/wildcard-method-selection/createPerson.action)
+
+will be be processed by the the above action mapping and method create of class PersonAction will be called. While this URL
+
+[http://localhost:8080/wildcard-method-selection/deletePerson.action](http://localhost:8080/wildcard-method-selection/deletePerson.action)
+
+will cause the delete method of class PersonAction to be called.
+
+What happens if we have a URL with nothing in front of Person? For example:
+
+[http://localhost:8080/wildcard-method-selection/Person.action](http://localhost:8080/wildcard-method-selection/Person.action)
+
+If there is no value in front of Person, then the Struts 2 framework will call the execute method of the class PersonAction.
+
+#####Dynamic Method Invocation#####
+
+The wildcard method selection technique explained above should not be confused with the "Dynamic Method Invocation" technique. The Struts 2 documentation explains this technique (which uses the bang, \!, operator in the action name) and recommends against using the "Dynamic Method Invocation" technique due to security and other reasons related to how this technique is implemented internally.
+
+The Struts 2 documentation also recommends turning off the option to use the dynamic method invocation by setting struts.enable.DynamicMethodInvocation to FALSE in the Struts configuration.
+
+#####Summary#####
+
+By using the wildcard method selection technique explained above, you can significantly reduce the number of action mapping nodes you need to write and manage in the Struts 2 XML configuration file.


Mime
View raw message