Return-Path: X-Original-To: apmail-struts-commits-archive@minotaur.apache.org Delivered-To: apmail-struts-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2F645C2F7 for ; Wed, 17 Jul 2013 09:33:15 +0000 (UTC) Received: (qmail 13768 invoked by uid 500); 17 Jul 2013 09:33:14 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 13739 invoked by uid 500); 17 Jul 2013 09:33:14 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 13726 invoked by uid 99); 17 Jul 2013 09:33:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Jul 2013 09:33:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Jul 2013 09:33:08 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 588392388CB2 for ; Wed, 17 Jul 2013 09:31:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r869821 [38/43] - in /websites/production/struts/content/development/2.x/docs: ./ ajax-validation.data/ big-picture.data/ chaining-interceptor.data/ colophon.data/ config-browser-plugin.data/ create-struts-2-web-application-using-maven-to-m... Date: Wed, 17 Jul 2013 09:31:13 -0000 To: commits@struts.apache.org From: lukaszlenart@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130717093130.588392388CB2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: websites/production/struts/content/development/2.x/docs/url-validator.html ============================================================================== --- websites/production/struts/content/development/2.x/docs/url-validator.html (added) +++ websites/production/struts/content/development/2.x/docs/url-validator.html Wed Jul 17 09:31:08 2013 @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + url validator + + + + + + + +
+  Home > Guides > Core Developers Guide > Validation > url validator + +
+ + + + + + +
+
+ +
+ + +
+
+
+

Description

+ +

URLValidator checks that a given field is a String and a valid URL

+ + +

Parameters

+ +

  • fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required
+ + + +

Examples

+
+ +
+
+ + +
+
+ + + \ No newline at end of file Added: websites/production/struts/content/development/2.x/docs/use-cases.html ============================================================================== --- websites/production/struts/content/development/2.x/docs/use-cases.html (added) +++ websites/production/struts/content/development/2.x/docs/use-cases.html Wed Jul 17 09:31:08 2013 @@ -0,0 +1,196 @@ + + + + + + + + + Use Cases + + + + + + + +
+  Home > Guides > Contributors Guide > Requirements > Use Cases + +
+ + + + + + +
+
+ +
+ + +
+
+
Under Construction
+ +

+

The primary actors and their general goals

+ +
+
Actor Goal
Client (Browser) ...
Developer  
Framework (System)  
Container  
Extension (Plug In)  
+
+ + + +

+

Business Use Cases (end user applications)

+ +
+
PriorityActorGoalStory or BriefIssue ID
  Client Obtain Response Client can submit a request and receive a customized response.  
  Framework Execute Action A request can invoke a pluggable handler written as a server-side class.  
    ...  
     
+
+ + +

+

Development Use Cases (application developers)

+ +
+
PriorityActorGoalStory or BriefIssue ID
  Developer Create Action How to create an Action class  
    ...  
     
+
+ + +

+

Framework Use Cases (framework developers)

+ +
+
PriorityActorGoalStory or BriefIssue ID
  Developer Zero Configuration Scanning How we configure actions using conventions and annotations  
    ...  
     
+
+ + +

See Also

+ +
+
+ +
+ Children + + Show Children + +
+ + +
+
+ + + \ No newline at end of file Added: websites/production/struts/content/development/2.x/docs/using-checkboxes-editactionjava.html ============================================================================== --- websites/production/struts/content/development/2.x/docs/using-checkboxes-editactionjava.html (added) +++ websites/production/struts/content/development/2.x/docs/using-checkboxes-editactionjava.html Wed Jul 17 09:31:08 2013 @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + Using Checkboxes - EditAction.java + + + + + + + +
+  Home > FAQs > Cookbook > Using Checkboxes > Using Checkboxes - EditAction.java + +
+ + + + + + +
+
+ +
+ + +
+
+
+
+ +
+
+ + +
+
+ + + \ No newline at end of file Added: websites/production/struts/content/development/2.x/docs/using-checkboxes.html ============================================================================== --- websites/production/struts/content/development/2.x/docs/using-checkboxes.html (added) +++ websites/production/struts/content/development/2.x/docs/using-checkboxes.html Wed Jul 17 09:31:08 2013 @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + Using Checkboxes + + + + + + + +
+  Home > FAQs > Cookbook > Using Checkboxes + +
+ + + + + + +
+
+ +
+ + +
+
+

The W3C specification does not provide a way to submit a "cleared" or "false" checkbox. If the control is clear, the browser will not submit any value for that control. The application is expected to notice that the checkbox was not submitted, and proceed accordingly.

+ +

The framework automatically tracks the checkboxes used by a form (so you don't have to). If a checkbox is missing, a default value for the checkbox (usually false) is injected. The checkbox control can then turn on-and-off values as needed,

+ +

Using Checkboxes to Set a Collection

+ +

Our user has a number of priviliges that are stored as a Set of strings. To use checkboxes for these, we have HTML that looks like:

+ +
+ +
+ +

Say a user checks the first 2; the browser will send the query string: user.priv=boss&user.priv=admin.

+ +

OGNL will end up calling

+ +
+ +

You can write this method like:

+
+ +
+

Full Detailed example:

+

This example uses a kind-of model-driven action (see Model Driven Interceptor). The action returns a single getter for the User object whose values are populated.

+ + +
+
+ +
+ Children + + Show Children + +
+ + +
+
+ + + \ No newline at end of file Added: websites/production/struts/content/development/2.x/docs/using-freemarker-templates.html ============================================================================== --- websites/production/struts/content/development/2.x/docs/using-freemarker-templates.html (added) +++ websites/production/struts/content/development/2.x/docs/using-freemarker-templates.html Wed Jul 17 09:31:08 2013 @@ -0,0 +1,426 @@ + + + + + + + + + + + + + + + + + Using Freemarker Templates + + + + + + + +
+  Home > Guides > User Guide > Using Freemarker Templates + +
+ + + + + + +
+
+ +
+ + +
+
+

FreeMarker is a Java-based template engine that is a great alternative to JSP. FreeMarker is ideal for situations where your action results can possibly be loaded from outside a Servlet container. For example, if you wished to support plugins in your application, you might wish to use FreeMarker so that the plugins could provide the entire action class and view in a single jar that is loaded from the classloader.

+ + + +

Configure your action to use the "freemarker" result type

+ +

Struts provides a result type "freemarker" which renders a FreeMarker template. This result type is defined in struts-default.xml. To create pages using FreeMarker, set the result type of the actions to "freemarker".

+ +
+ +
+ + +

Using properties

+ +

FreeMarker uses the ${...} notation to access properties. They are called interpolations. Properties on the actions (getter methods) will automatically be available on the FreeMarker templates. If an action has a "getName()" method, then its value can be inserted on the template like:

+ +
+ +
+ +
Be Careful
By default, FreeMarker will throw an error if it finds a variable that is not defined, or has a null value. See this FAQ for details.
+ + +

Servlet / JSP Scoped Objects

+ +

The following are ways to obtained Application scope attributes, Session scope attributes, Request scope attributes, Request parameters, and framework Context scope parameters:-

+ +

Application Scope Attribute

+ +

Assuming there's an attribute with name myApplicationAttribute in the Application scope.

+
+ +
+

or

+
+ +
+ +

Session Scope Attribute

+ +

Assuming there's an attribute with name mySessionAttribute in the Session scope.

+
+ +
+

or

+
+ +
+ +

Request Scope Attribute

+ +

Assuming there's an attribute with name 'myRequestAttribute' in the Request scope.

+
+ +
+

or

+
+ +
+ +

Request Parameter

+ +

Assuming there's a request parameter myParameter (eg. http://host/myApp/myAction.action?myParameter=one).

+
+ +
+

or

+
+ +
+ +

Context parameter

+ +

Assuming there's a parameter with the name myContextParam in framework context.

+
+ +
+

or

+
+ +
+ +

Template Loading

+ +

The framework looks for FreeMarker templates in two locations (in this order):

+
  1. Web application
  2. Class path
+ + +

This ordering makes it ideal for providing templates inside a fully-built jar, but allowing for overrides of those templates to be defined in your web application. In fact, this is how you can override the default UI tags and Form Tags included with the framework.

+ +

In addition, you can specify a location (directory on your file system) through the templatePath or TemplatePath context variable (in the web.xml. If a variable is specified, the content of the directory it points to will be searched first.

+ +
This variable is currently NOT relative to the root of your application.
+ + +

If a property is defined on the template with the same name as a property on the action, FreeMarker will use the property defined on the template.

+ + + +

Variable Resolution

+ +

When using FreeMarker with the framework, variables are looked up in several different places, in this order:

+
  1. Built-in variables
  2. Value stack
  3. Action context
  4. Request scope
  5. Session scope
  6. Application scope
+ + +

Note that the action context is looked up after the value stack. This means that you can reference the variable without the typical preceding has marker (#) like you would have to when using the JSP s:property tag. This is a nice convenience, though be careful because there is a small chance it could trip you up.

+
+ +
+

The built-in variables that Struts-FreeMarker integration provides are:

+
+
Name Description
stack The value stack itself, useful for calls like ${stack.findString('ognl expr')}
action The action most recently executed
response The HttpServletResponse
res Same as response
request The HttpServletRequest
req Same as request
session The HttpSession
application The ServletContext
base The request's context path
+
+ + + +

FreeMarker configuration

+ +

To configure the FreeMarker engine, just add a file freemarker.properties to the classpath. The supported properties are those that the FreeMarker Configuration object expects, see FreeMarker's documentation for more details.

+ +
freemarker.properties example
+ +
+ + +

Tags

+ + +

Using Struts tags

+ +

Tags distributed with Struts are automatically made available to FreeMarker templates. To use any tag add "@s." in front of the tag name. Like:

+ +
Using Struts tags on FreeMarker templates
+ +
+ + +

Using JSP tags

+ +

To use JSP tags that are not part of Struts you have to:

+ +

1. Add JspSupportSerlvet to web.xml

+ +
Adding JspSupportSerlvet to web.xml
+ +
+ +

2. Declare the tld on web.xml or use FreeMarker's "assign" directive. When using the "assign" directive, provide the absolute path to the tld file.

+ +
Using JSP tags on FreeMarker templates
+ +
+ + +

Tips and Tricks

+ +

There are some advanced features that may be useful when building Struts applications with FreeMarker.

+ + +

Type Conversion and Locales

+ +

FreeMarker has built in support for formatting dates and numbers. The formatting rules are based on the locale associated with the action request, which is by default set in struts.properties but can be over-ridden using the I18n Interceptor. This is normally perfect for your needs, but it is important to remember that these formatting rules are handled by FreeMarker and not by the framework's Type Conversion support.

+ +

If you want the framework to handle the formatting according to the Type Conversion you have specified, you shouldn't use the normal ${...} syntax. Instead, you should use the property tag. The difference is that the property tag is specifically designed to take an OGNL expression, evaluate it, and then convert it to a String using any Type Conversion rules you have specified. The normal ${...} syntax will use a FreeMarker expression language, evaluate it, and then convert it to a String using the built in formatting rules.

+ +
The difference in how type conversion is handled under Freemarker is subtle but important to understand.
+ + +

String and Non String Values on tags

+ +

In FreeMarker it is incorrect to quote non string values. If a value is quoted, then an string will be passed, instead of the expected object, causing an exception. For example, the "textarea" tag expects the attributes "rows" and "cols" of type Integer:

+ +
Do not quote non string values in tag attributes!
+ +
+ + +

Extending

+ +

Sometimes you may with to extend the framework's FreeMarker support. For example, you might want to extend the Struts tags that come bundled with the framework.

+ +

To extend the Freemarker support, develop a class that extends org.apache.struts2.views.freemarker.FreemarkerManager, overriding methods as needed, and plugin the class through the struts.properties:

+
+ +
+ + +

FreeMarker alternative syntax

+ +

FreeMarker by default uses the "<#directive />" syntax. FreeMarker supports an alternative syntax, where [ and ] are used instead of < and >. To enable the alternative syntax, add [#ftl] at the beginning of the template. The alternative syntax makes it easier to differentiate between FreeMarker directives, and JSP or HTML tags.

+ +
Use alternative syntax
+ +
+ +

There are a number of IDE plugins available for FreeMarker. But, if your IDE is not on the list, then the using alternative syntax will avoid conflicts between FreeMarker and the HTML syntax highlighting provided by your IDE.

+ +

FreeMarker links

+ + + +
+
+ + +
+
+ + + \ No newline at end of file Added: websites/production/struts/content/development/2.x/docs/using-non-field-validators.html ============================================================================== --- websites/production/struts/content/development/2.x/docs/using-non-field-validators.html (added) +++ websites/production/struts/content/development/2.x/docs/using-non-field-validators.html Wed Jul 17 09:31:08 2013 @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + Using Non Field Validators + + + + + + + +
+  Home > Guides > Core Developers Guide > Validation > Using Non Field Validators + +
+ + + + + + +
+
+ +
+ + +
+
+

Description

+

The followings show a simple example using Webwork's Non Field Validators

+ +

Step 1

+

Create the jsp page

+
+ +
+ + +

Step 2

+

Create the action class

+
+ +
+ + +

Step 3

+

Create the validator.xml.

+
+ +
+ +
+
+ + +
+
+ + + \ No newline at end of file