This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/struts-site.git
commit d5cfe24b25cb866855b49ce7dc43cb76c5434d26 Author: Lukasz Lenart <lukaszlen...@apache.org> AuthorDate: Wed Nov 15 08:38:03 2017 +0100 Adds ToC --- source/getting-started/coding-actions.md | 4 ++++ source/getting-started/control-tags.md | 12 ++++++++---- source/getting-started/exception-handling.md | 16 ++++++++++------ source/getting-started/form-tags.md | 20 ++++++++++++-------- source/getting-started/form-validation-using-xml.md | 20 ++++++++++++-------- .../how-to-create-a-struts2-web-application.md | 5 +++++ source/getting-started/jasper-reports-tutorial.md | 4 ++++ source/getting-started/processing-forms.md | 4 ++++ source/getting-started/wildcard-method-selection.md | 14 +++++++++----- 9 files changed, 68 insertions(+), 31 deletions(-) diff --git a/source/getting-started/coding-actions.md b/source/getting-started/coding-actions.md index cd45a74..ccc83ea 100644 --- a/source/getting-started/coding-actions.md +++ b/source/getting-started/coding-actions.md @@ -7,6 +7,10 @@ parent: --- # Coding actions +{:.no_toc} + +* Will be replaced with the ToC, excluding a header +{:toc} This tutorial assumes you've completed the [Using Struts 2 Tags](using-tags.html) tutorial and have a working using-tags project. The example code for this tutorial, coding-actions, is available for checkout from the Struts 2 GitHub repository: [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples). diff --git a/source/getting-started/control-tags.md b/source/getting-started/control-tags.md index a8bf1cf..f33a799 100644 --- a/source/getting-started/control-tags.md +++ b/source/getting-started/control-tags.md @@ -7,16 +7,20 @@ parent: --- # Control Tags +{:.no_toc} + +* Will be replaced with the ToC, excluding a header +{:toc} The example code for this tutorial, control_tags, is available at [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples) -__Introduction__ +## Introduction Struts 2 has several control tags that can be used in the view. This tutorial will discuss and show examples of how to use the Struts 2 if and iterator tags. For more information about these and other control tags visit [tags reference](http://cwiki.apache.org/confluence/display/WW/Generic+Tag+Reference). The [Struts 2 user mailing list](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. -__Struts 2 if Tag__ +## Struts 2 if Tag In the example application's thankyou.jsp is this markup. @@ -48,7 +52,7 @@ The value of the test attribute must be an expression that evaluates to true or The purpose of the above markup is to use either "Car model" or "Car models" depending on how many car models the user selected on the edit page. So the value for the test attribute of this iterator tag gets the length of the carModels String array and compares that to 1. If it's greater then 1, the correct grammar is "Car models" else the correct grammar is "Car model". -__Struts iterator Tag__ +## Struts iterator Tag The Struts iterator tag is used to generate a loop that iterates over each item in a collection. In the thankyou.jsp is this markup. @@ -78,7 +82,7 @@ If the collection contains objects that have multiple fields, then you should us The value of the iterator tag is states, which causes the Struts 2 framework to call the getStates method of the Action class (`EditAction.java`). The getStates method returns a List of State objects. The State class has two fields stateAbbr and stateName, both having the appropriate get method. The iterator will loop over each State object stored in the collection. Each time through the loop, the Struts 2 framework will have a reference to the current State object and will call getState [...] -__Additional Iterator Attributes__ +## Additional Iterator Attributes The Struts 2 iterator tag has additional attributes you can use to control the begin and end values for specifying that the iterator tag should only loop over a part of the collection. See the [iterator tag reference](https://cwiki.apache.org/confluence/display/WW/iterator) for more information. diff --git a/source/getting-started/exception-handling.md b/source/getting-started/exception-handling.md index b7f67af..41292ee 100644 --- a/source/getting-started/exception-handling.md +++ b/source/getting-started/exception-handling.md @@ -7,16 +7,20 @@ parent: --- # Exception Handling +{:.no_toc} + +* Will be replaced with the ToC, excluding a header +{:toc} The code for this tutorial, exception_handling, is available for checkout at [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples). -__Introduction__ +## Introduction In this tutorial we'll explore how to enable the Struts 2 framework to handle any uncaught exceptions generated by a web application. Struts 2 provides robust exception handling, including the ability to automatically log any uncaught exceptions and redirect the user to a error web page. The [Struts 2 user mailing list](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. -__Global Exception Handling__ +## Global Exception Handling Using the Struts 2 framework you can specify in the struts.xml how the framework should handle uncaught exceptions. The handling logic can apply to all actions (global exception handling) or to a specific action. Let's first discuss how to enable global exception handling. @@ -38,7 +42,7 @@ The global exception mapping node tells the Struts 2 framework what to do if an The global results mapping node relates the result value to a specific view page. For example the result "securityerror" will cause the framework to redirect the user's browser to the securityerror.jsp view page. -__Exception Handling Per Action__ +## Exception Handling Per Action If you need to handle an exception in a specific way for a certain action you can use the exception-mapping node within the action node. @@ -54,7 +58,7 @@ The above action node from the example application's struts.xml file specifies t You can see that an action-specific exception mapping will take precedence if the same exception is also mapped globally. -__Logging Exceptions__ +## Logging Exceptions You can configure the Struts 2 framework to log any uncaught exceptions. To enable logging of the exceptions being handled by the Struts 2 framework you must specify some parameter values in struts.xml. If you examine the [ExceptionMappingInterceptor class API](https://struts.apache.org/maven/struts2-core/apidocs/com/opensymphony/xwork2/interceptor/ExceptionMappingInterceptor.html) there are three parameter values you can set to enable logging (logEnabled), the log level to use (logLevel [...] @@ -81,7 +85,7 @@ Now when the application throws an uncaught exception, the Struts 2 framework wi In the example applications, the logging is just to the Servlet container's console (see the `log4j.xml` file for the log settings). -__Display Exception Information In Browser__ +## Display Exception Information In Browser You can display information about the exception in the browser if you want by using s:property tags with a value of exception and exceptionStack. For example in error.jsp is this markup. @@ -97,7 +101,7 @@ You can display information about the exception in the browser if you want by us When the exception interceptor is triggered it adds to the fields available for display the exception message and the exception's stack trace. -__Summary__ +## Summary Struts 2 provides a easy to use configuration for handling uncaught exceptions and redirecting users to appropriate view pages. You can configure exception handling to be global for all actions or to just for a specific action. You can also enable the Struts 2 framework to log the uncaught exceptions. diff --git a/source/getting-started/form-tags.md b/source/getting-started/form-tags.md index b1ef021..8888ad8 100644 --- a/source/getting-started/form-tags.md +++ b/source/getting-started/form-tags.md @@ -7,10 +7,14 @@ parent: --- # Form Tags +{:.no_toc} + +* Will be replaced with the ToC, excluding a header +{:toc} The example code for this tutorial, form_tags, can be checked out from [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples). -__Introduction__ +## Introduction In this tutorial we'll explore some of the other Struts 2 form controls. In our previous tutorials that explained how to use Struts 2 forms ([Processing forms](processing-forms.html), [Form validation](form-validation.html), @@ -22,7 +26,7 @@ The [Struts 2 user mailing list](http://struts.apache.org/mail.html) is an excel 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__ +## Example Application The example application that supports this tutorial shows how to use Struts 2 form tags so that a user can edit his information. The information that can be edited is encapsulated in an object of class Person. A Person object knows @@ -39,7 +43,7 @@ of the Person object. The first and last names are shown on the form (see edit.jsp) using the Struts 2 textfield tag, which we've discussed in previous tutorials. -__Struts 2 Select Tag__ +## Struts 2 Select Tag A user can select one favorite sport from several choices. The example application uses the Struts 2 select tag to provide the list of options for the select box. @@ -95,7 +99,7 @@ head section. Since the personBean's getSport method returns "baskeball", the basketball option value is marked as selected. -__Struts 2 Radio Tag__ +## Struts 2 Radio Tag The Struts 2 radio tag—like its standard HTML counterpart—is used to display 2 or more choices, only one of which can be selected by the user. Here is the code for the Struts 2 radio button from the example application. @@ -134,7 +138,7 @@ The Array of String objects returned are used to create the individual radio but Also just like the Struts 2 select tag the result returned by calling the personBean object's getGender method is used to determine which of the radio buttons is checked. -__Struts 2 Select Tag - Object Backed__ +## Struts 2 Select Tag - Object Backed You may need to create a Struts 2 select tag where the options displayed to the user each have their own value that is different then what is displayed. In the example application, the user's residency is stored as a two-letter @@ -177,7 +181,7 @@ The value returned by calling the personBean object's getResidency method determ tags is marked as selected. In our example, since getResidency returns "KS", the option tag whose value attribute equals "KS" is marked as selected. -__Struts 2 Checkbox Tag__ +## Struts 2 Checkbox Tag The Struts 2 checkbox tag is used to create the HTML input type equals checkbox tag. The value for the key attribute tells the framework what method to call to determine if the checkbox is checked or not checked. The method called should @@ -216,7 +220,7 @@ hidden form field to check if the associated checkbox field exists in the posted doesn't exist then the Struts 2 framework will know to update the value of the personBean object's over21 instance variable to false. -__Struts 2 checkboxlist Tag__ +## Struts 2 checkboxlist Tag The Struts 2 framework provides a unique form field control that creates a series of associated check boxes, one or more of which can be checked. In the example application, the Person class has an Array of Strings, which is used to store @@ -266,7 +270,7 @@ the checkbox will be checked. </tr> ``` -__Summary__ +## Summary There are several other Struts 2 form controls you should explore. If you need more information about the Struts 2 form tags consult the Struts 2 documentation at [http://struts.apache.org](http://struts.apache.org). diff --git a/source/getting-started/form-validation-using-xml.md b/source/getting-started/form-validation-using-xml.md index 41180c1..268bfe8 100644 --- a/source/getting-started/form-validation-using-xml.md +++ b/source/getting-started/form-validation-using-xml.md @@ -7,16 +7,20 @@ parent: --- # Form Validation Using XML +{:.no_toc} + +* Will be replaced with the ToC, excluding a header +{:toc} The example code for this tutorial, form_xml_validation, is available for checkout at [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples) -__Introduction__ +## Introduction In this tutorial we'll cover how to validate a user's input in form fields using Struts 2's XML validation methodology. In the [Form Validation](form-validation.html) tutorial we discussed validating a user's input using the validate method in the Action class. Using a separate XML validation file gives you the ability to use validators built-in to the Struts 2 framework. The [Struts 2 user mailing list](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__ +## Example Application The example application that supports this tutorial shows how to use Struts 2's XML validation methodology. The information that can be edited is encapsulated in an object of class Person. @@ -26,7 +30,7 @@ To enable the user to edit his information that is stored in the Person object, When the user submits the form, we want to validate his entries into the form fields. -__Validation Using XML__ +## Validation Using XML To validate a user's form field entries you can use a separate XML file that contains your validation rules. The XML file that contains the validation rules must be named as ActionClassName-validation.xml. In the example application, the XML validation file is named EditAction-validation.xml (see src/main/resources/org/apache/struts/edit/action). @@ -34,7 +38,7 @@ Struts 2 provides several different validators that you can use in the XML valid In the above form, we want to ensure the user enters a first name. To have the Struts 2 framework enforce that rule we can used the Struts 2 [requiredstring validator](../core-developers/requiredstring-validator.html). This validator checks that the user has entered a string value in the form field. -__XML Validator Format__ +## XML Validator Format In the XML validation file (for this example that is EditAction-validation.xml), is this XML: @@ -59,7 +63,7 @@ For example if the user doesn't enter a value in the first name form field and c ![form-validation-2.png](attachments/att20873264_form-validation-2.png) -__Validating An Email Address__ +## Validating An Email Address You can use the Struts 2 [email validator](../core-developers/email-validator.html) to validate the user's input in the email field. Here is the validator node that is in the `EditAction-validation.xml` file. @@ -78,7 +82,7 @@ You can use the Struts 2 [email validator](../core-developers/email-validator.ht Note that in the example, we are requiring the user to enter an email address and then validating the email address the user entered. -__Validating A User's Input Using A Regular Expression__ +## Validating A User's Input Using A Regular Expression The Struts 2 framework provides a powerful way to validate a user's form field input by using the [regex validator](../core-developers/regex-validator.html) . In the example application, we want to ensure the user enters the phone number in the format 999-999-9999. We can use a regular expression and the [regex validator](../core-developers/regex-validator.html) to enforce this rule. @@ -98,7 +102,7 @@ The Struts 2 framework provides a powerful way to validate a user's form field i The param name="expression" node is used to specify the regular expression that will be applied to the user's input. Note how the regular expression is contained within a CDATA section. -__Validating A User's Input Using An OGNL Expression__ +## Validating A User's Input Using An OGNL Expression In the example application, we want to ensure the user checks at least one of the car model check boxes. To enforce this rule we can use the [fieldexpression validator](../core-developers/fieldexpression-validator.html) . Here's the XML for that validator node. @@ -122,7 +126,7 @@ If the user did not check any of the check boxes, the Array returned by the getC The fieldexpression validator is useful when doing conditional validation of a user's input. If the OGNL expression doesn't evaluate to true then the user's input won't be allowed. -__Summary__ +## Summary The Struts 2 framework provides easy-to-use validation methodologies. You can add a validate method to the Action class or have a separate XML file with validation rules or you can use a combination of both methodologies. diff --git a/source/getting-started/how-to-create-a-struts2-web-application.md b/source/getting-started/how-to-create-a-struts2-web-application.md index 997ffa4..bb48478 100644 --- a/source/getting-started/how-to-create-a-struts2-web-application.md +++ b/source/getting-started/how-to-create-a-struts2-web-application.md @@ -5,7 +5,12 @@ parent: title: Getting started url: index.html --- + # How To Create A Struts 2 Web Application +{:.no_toc} + +* Will be replaced with the ToC, excluding a header +{:toc} This tutorial walks through installing the framework and creating a simple application. diff --git a/source/getting-started/jasper-reports-tutorial.md b/source/getting-started/jasper-reports-tutorial.md index 8c5bf86..b349420 100644 --- a/source/getting-started/jasper-reports-tutorial.md +++ b/source/getting-started/jasper-reports-tutorial.md @@ -7,6 +7,10 @@ parent: --- # JasperReports Tutorial +{:.no_toc} + +* Will be replaced with the ToC, excluding a header +{:toc} The Struts 2 JasperReports plugin is a bridge from Struts 2 to JasperReports and does not include JasperReports itself, which must be downloaded separately. diff --git a/source/getting-started/processing-forms.md b/source/getting-started/processing-forms.md index 8d3ffe3..b81c452 100644 --- a/source/getting-started/processing-forms.md +++ b/source/getting-started/processing-forms.md @@ -7,6 +7,10 @@ parent: --- # Processing Forms +{:.no_toc} + +* Will be replaced with the ToC, excluding a header +{:toc} This tutorial assumes you've completed the [Coding Struts 2 Actions](coding-actions.html) tutorial and have a working coding-actions project. The example code for this tutorial, form-processing, is available for checkout from diff --git a/source/getting-started/wildcard-method-selection.md b/source/getting-started/wildcard-method-selection.md index 44e1bcd..841a4c7 100644 --- a/source/getting-started/wildcard-method-selection.md +++ b/source/getting-started/wildcard-method-selection.md @@ -7,22 +7,26 @@ parent: --- # Wildcard Method Selection +{:.no_toc} + +* Will be replaced with the ToC, excluding a header +{:toc} 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__ +## 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) 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__ +## 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 [...] -__Wildcard Method Selection__ +## 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: @@ -69,13 +73,13 @@ What happens if we have a URL with nothing in front of Person? For example: 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__ +## 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__ +## 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. -- To stop receiving notification emails like this one, please contact "commits@struts.apache.org" <commits@struts.apache.org>.