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
The following commit(s) were added to refs/heads/master by this push: new 8e1fdf7 Cleans up section about templates 8e1fdf7 is described below commit 8e1fdf75510a69cdcdb88aeaf10957f075c5d005 Author: Lukasz Lenart <lukaszlen...@apache.org> AuthorDate: Sun Sep 24 21:04:05 2017 +0200 Cleans up section about templates --- source/tag-developers/ajax-a-template.md | 24 ++ source/tag-developers/ajax-div-template.md | 161 ++++++++++ source/tag-developers/ajax-event-system.md | 38 +++ source/tag-developers/ajax-head-template.md | 25 ++ source/tag-developers/ajax-theme.md | 439 +++------------------------- source/tag-developers/css-xhtml-theme.md | 171 ++++------- source/tag-developers/simple-theme.md | 40 ++- source/tag-developers/xhtml-theme.md | 252 +++++----------- 8 files changed, 439 insertions(+), 711 deletions(-) diff --git a/source/tag-developers/ajax-a-template.md b/source/tag-developers/ajax-a-template.md new file mode 100644 index 0000000..42301ea --- /dev/null +++ b/source/tag-developers/ajax-a-template.md @@ -0,0 +1,24 @@ +--- +layout: default +title: Tag Developers Guide (WIP) +--- + +# ajax a template + +The ajax theme is experimental. Feedback is appreciated. + +The ajax a template is used to make asynchronous calls to the server when the user clicks on the a href link. It is +useful when you need to communicate information back to the application from the UI, without requiring the entire page +to be re-rendered. An example would be removing an item from a list. + +The `preInvokeJS` attribute is used to determine whether the URL specified should be called or not, and must contain +Javascript that returns `true` or `false`. If you want to call a JavaScript function, use the format +`preInvokeJS='yourMethodName(data,type)'`. An example would be to show a confirm dialog to the user to double check +whether they want to remove a user from a list. + +**Remember**: the content returned by the `href` attribute must be JavaScript. That JavaScript will then be evaluated +within the webpage. If you only wish to publish an event to the topic specified, then simply return no result (or `NONE`) +from your action and utilize the `notifyTopics` attribute to specific the topic names. + +For an example of the interaction between the [div](dojo-div-tag.html) tag and the [a](dojo-a-tag.html) tag using +the topic pub/sub model, see the examples in the [ajax div template](ajax-div-template.html). diff --git a/source/tag-developers/ajax-div-template.md b/source/tag-developers/ajax-div-template.md new file mode 100644 index 0000000..8fbc82b --- /dev/null +++ b/source/tag-developers/ajax-div-template.md @@ -0,0 +1,161 @@ +--- +layout: default +title: Tag Developers Guide (WIP) +--- + +# ajax div template + +> The Ajax theme is experimental. Feedback is appreciated. + +The ajax [div](dojo-div-tag.html) template provides a much more interesting div rendering option that the other themes +do. Rather than simply rendering a `<div>` tag, this template relies on advanced AJAX features provided +by the [Dojo Toolkit](http://dojotoolkit.org). While the [div](dojo-div-tag.html) tag could be used outside +of the [ajax theme](), it is usually not very useful. See the [div](dojo-div-tag.html) tag for more information on what +features are provided. + +## Features + +The remote div has a few features, some of which can be combined with the [a](dojo-a-tag.html) tag and +the [ajax a template](ajax-a-template.html). These uses are: + +- Retrieve remote data +- Initialize the div with content before the remote data is retrieved +- Display appropriate error and loading messages +- Refresh data on a timed cycle +- Listen for events and refresh data +- JavaScript control support + +## Retrieve Remote Data + +The simplest way to use the div tag is to provide an `href` attribute. For example: + +```html +<saf:div theme="ajax" id="weather" href="http://www.weather.com/weather?zip=97239"/> +``` + +What this does after the HTML page is completely loaded, the specified URL will be retrieved asynchronously +in the browser. The entire contents returned by that URL will be injected in to the div. + +## Initializing the Div + +Because the remote data isn't loaded immediately, it is sometimes useful to have some placeholder content that exists +before the remote data is retrieved. The content is essentially just the body of the div element. For example: + +```html +<saf:div theme="ajax" id="weather" href="http://www.weather.com/weather?zip=97239"> + Placeholder... +</saf:div> +``` + +If you wish to load more complex initial data, you can use the [action](action-tag.html) tag and the `executeResult` +attribute: + +```html +<saf:div theme="ajax" id="weather" href="http://www.weather.com/weather?zip=97239"> + <ww:action id="weather" name="weatherBean" executeResult="true"> + <ww:param name="zip" value="97239"/> + </ww:action> +</saf:div> +``` + +## Loading and Error Messages + +If you'd like to display special messages when the data is being retrieved or when the data cannot be retrieved, you can +use the `errorText` and `loadingText` attributes: + +```html +<saf:div theme="ajax" id="weather" href="http://www.weather.com/weather?zip=97239" + loadingText="Loading weather information..." + errorText="Unable to contact weather server"> + Placeholder... +</saf:div> +``` + +## Refresh Timers + +Another feature this div template provides is the ability to refresh data on a timed basis. Using the `updateFreq` +and the `delay` attributes, you can specify how often the timer goes off and when the timer starts (times in milliseconds). +For example, the following will update every minute after a two second delay: + +```html +<saf:div theme="ajax" id="weather" href="http://www.weather.com/weather?zip=97239" + loadingText="Loading weather information..." + errorText="Unable to contact weather server"> + delay="2000" + updateFreq="60000" + Placeholder... +</saf:div> +``` + +## Listening for Events + +The [a](dojo-a-tag.html) tag (specifically the [ajax a template](ajax-a-template.html)) and the div tag support +an [ajax event system](ajax-event-system.html), providing the ability to broadcast events to topics. You can specify +the **topics** to listen to using a comma separated list in the `listenTopics` attribute. What this means is that when +a topic is published, usually through the [ajax a template](ajax-a-template.html), the URL specified in the `href` +attribute will be re-requested. + +```html +<saf:div theme="ajax" id="weather" href="http://www.weather.com/weather?zip=97239" + loadingText="Loading weather information..." + errorText="Unable to contact weather server" + listenTopics="weather_topic,some_topic"> + Placeholder... +</saf:div> +<saf:a id="link1" + theme="ajax" + href="refreshWeather.action" + notifyTopics="weather_topic,other_topic" + errorText="An Error ocurred">Refresh</saf:a> +``` + +## JavaScript Support + +There are also javascript functions to refresh the content and stop/start the refreshing of the component. +For the remote div with the component id `remotediv1`: + +To start refreshing use the javascript: + +```javascript +remotediv1.startTimer(); +``` +To stop refreshing use the javascript: + +```javascript +remotediv1.stopTimer(); +``` +To refresh the content use the javascript: + +```javascript +remotediv1.refresh(); +``` + +## JavaScript Examples + +To further illustrate these concepts here is an example. Say you want to change the url of a div at runtime via javascript. +Here is what you need to do: + +What you will need to do is add a JS function that listens to a JS event that publishes the id from the select box that +was selected. It will modify the URL for the div (adding the id so the correct data is obtained) and then `bind()` +the AJAX div so it refreshes. + +```html +<saf:head theme="ajax" /> + +<script type="text/javascript"> + function updateReports(id) { + var reportDiv= window['reportDivId']; + reportDiv.href = '/../reportListRemote.action?selectedId='+id; + reportDiv.refresh(); + } + dojo.event.topic.getTopic("updateReportsListTopic").subscribe(null, "updateReports"); +</script> + +<form ... > +<saf:select .... onchange="javascript: dojo.event.topic.publish("updateReportsListTopic", this.value); " /> + +<saf:div id="reportDivId" theme="ajax" href="/.../reportListRemote.action" > + Loading reports... +</saf:div> +</form> +``` diff --git a/source/tag-developers/ajax-event-system.md b/source/tag-developers/ajax-event-system.md new file mode 100644 index 0000000..aaff715 --- /dev/null +++ b/source/tag-developers/ajax-event-system.md @@ -0,0 +1,38 @@ +--- +layout: default +title: Tag Developers Guide (WIP) +--- + +# ajax event system + +As you may have seen with the [ajax div template](ajax-div-template.html) and [ajax a template](ajax-a-template.html), +the framework and Dojo provide a nice way to subscribe and notify of topics from within the browser. A benefit of using +Dojo as the basis of many of these components is being able to loosely couple UI components. There are two +attributes of importance: `listenTopics` and `notifyTopics`. + +- If a component has a `notifyTopics` attribute, then after the processing has been completed a message with be published + to the topic names supplied as a value (comma delimited). +- If a component has a `listenTopics` attribute, then when a message is published to the topic names supplied as a value + (comma delimited), the component will perform custom tag-specific logic ( i.e a DIV tag will re-fresh its content). + +As well as this, you can publish and subscribe to topic names with javascript code. To publish to the `topic_name` topic: + +```java +dojo.event.topic.publish("topic_name", "content"); +``` + +The `topic_name` attribute is required, the content attribute is not and most elements are triggered without having this +attribute. See the [ajax div template](ajax-div-template.html) for an example of this type of interaction. + +To subscribe to the `topic_name` topic: + +```javascript +function doSomethingWithEvent(data) { +... +} + +dojo.event.topic.getTopic("topic_name").subscribe(null, "doSomethingWithEvent"); +``` + +The `subscribe` method takes 2 parameters, the first is the JavaScript object variable (or null if the function is not +from an object) and the second is the name of the function to call when an event is received on the topic. diff --git a/source/tag-developers/ajax-head-template.md b/source/tag-developers/ajax-head-template.md new file mode 100644 index 0000000..3686080 --- /dev/null +++ b/source/tag-developers/ajax-head-template.md @@ -0,0 +1,25 @@ +--- +layout: default +title: Tag Developers Guide (WIP) +--- + +# ajax head template + +The ajax [head](dojo-head-tag.html) template builds upon the [xhtml head template](head-tag.html) by providing additional +JavaScript includes for the [Dojo Toolkit](http://dojotoolkit.org), which is used by the [ajax a template](ajax-a-template.html), +[ajax div template](ajax-div-template.html), and the [ajax tabbedPanel template](). It is required to use this tag, +`<ww:head theme="ajax"/>` , in your HTML `<head>` block if you wish to use AJAX feature. The contents of **head.ftl** are: + +{% tag_attributes ajax/head.ftl %} + +> If you are having trouble getting the AJAX theme to work, you should include the above JavaScript in your page manually, +> changing "isDebug: false" to "isDebug: true". This will log out debugging information directly to the screen. + +Note that Dojo is configured to use the same character encoding specified in `struts.xml` , typically UTF-8. For a simple +example of how to use the [head](dojo-head-tag.html) tag with the AJAX theme, simply do the following in your HTML: + +{% highlight html %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/apps/showcase/src/main/webapp/ajax/commonInclude.jsp %} +{% endhighlight %} + +> The above sample is from Struts trunk; for 2.0.6 you should use `<s:head debug="true"/>`. diff --git a/source/tag-developers/ajax-theme.md b/source/tag-developers/ajax-theme.md index 5c2061a..5b5528e 100644 --- a/source/tag-developers/ajax-theme.md +++ b/source/tag-developers/ajax-theme.md @@ -5,55 +5,40 @@ title: Tag Developers Guide (WIP) # ajax theme +> The ajax theme is deprecated! -The ajax theme is deprecated! +The ajax theme extends the [xhtml theme](xhtml-theme.html) with AJAX features. The theme uses the popular DOJO +AJAX/JavaScript toolkit. AJAX features include: -| +- [AJAX Client Side Validation](../core-developers/ajax-client-side-validation.html) +- Remote [form](form-tag.html) submission support (works with the [submit](dojo-submit-tag.html) tag as well) +- An advanced [div](dojo-div-tag.html) template that provides dynamic reloading of partial HTML +- An advanced [a](dojo-a-tag.html) template that provides the ability to load and evaluate JavaScript remotely +- An AJAX-only [tabbedpanel](dojo-tabbedpanel-tag.html) implementation +- A rich pub-sub event model +- Interactive autocomplete tag -The ajax theme extends the [xhtml theme](#PAGE_13834) with AJAX features. The theme uses the popular DOJO AJAX/JavaScript toolkit. AJAX features include: +> See also: [Ajax tags](ajax-tags.html) -+ _AJAX Client Side Validation_ +## Browser Compatibility -+ Remote [form](#PAGE_14201) submission support (works with the [submit](#PAGE_14054) tag as well) +AJAX (as a technology) uses a browser-side scripting component that varies between browsers (and sometimes versions). +To hide those differences from the developer, we utilize the dojo toolkit ([http://www.dojotoolkit.org](http://www.dojotoolkit.org)). +Several browsers are supported by dojo, and any UI's created with the ajax theme should act the same way for supported +browsers. The supported browsers are: -+ An advanced [div](#PAGE_13908) template that provides dynamic reloading of partial HTML +- IE 5.5\+ +- FF 1.0\+ +- Latest Safari (on up-to-date OS versions) +- Latest Opera +- Latest Konqueror -+ An advanced [a](#PAGE_14027) template that provides the ability to load and evaluate JavaScript remotely +## Extending the AJAX Theme -+ An AJAX-only [tabbedPanel](#PAGE_14222) implementation - -+ A rich pub-sub event model - -+ Interactive autocomplete tag - - (ok) See also: _Ajax tags_ - -__Browser Compatibility__ - -AJAX (as a technology) uses a browser-side scripting component that varies between browers (and sometimes versions). To hide those differences from the developer, we utilize the dojo toolkit ([http://www.dojotoolkit.org](http://www.dojotoolkit.org)). Several browsers are supported by dojo, and any UI's created with the ajax theme should act the same way for supported browsers. The supported browsers are: - -+ IE 5.5\+ - -+ FF 1.0\+ - -+ Latest Safari (on up-to-date OS versions) - -+ Latest Opera - -+ Latest Konqueror - -__Extending the AJAX Theme__ - -The wrapping technique utilized by the ajax theme is much like [xhtml theme](#PAGE_13834), but the - -~~~~~~~ -controlheader.ftl -~~~~~~~ - is a wee bit different. - - -~~~~~~~ +The wrapping technique utilized by the ajax theme is much like [xhtml theme](xhtml-theme.html), but the `controlheader.ftl` +is a wee bit different. +```injectedfreemarker <#if parameters.label?if_exists != ""> <#include "/${parameters.templateDir}/xhtml/controlheader.ftl" /> </#if> @@ -65,367 +50,25 @@ controlheader.ftl ${tag.addParameter('onblur', "validate(this);")} </#if> </#if> +``` -~~~~~~~ - -The header provides for _AJAX Client Side Validation_ by checking if the - -~~~~~~~ -validate -~~~~~~~ - attribute is set to true. If it is, a validation request is made on each - -~~~~~~~ -onblur -~~~~~~~ - event for a HTML [Struts Tags](#PAGE_14248). Some people don't like the - -~~~~~~~ -onblur -~~~~~~~ - behavior; they would rather a more advanced timer (say, 200ms) be kicked off after every keystroke. You can override this template and provide that type of behavior if you would like. - -__Special Interest__ - -Three ajax_xhtml templates of special interest are - -~~~~~~~ -head -~~~~~~~ -, - -~~~~~~~ -div -~~~~~~~ -, and - -~~~~~~~ -a -~~~~~~~ -. - - - -| Especially with the ajax theme, it is important to use the [head](#PAGE_13997) tag. (See the _ajax head template_ for more information.) Without it, AJAX support may not be set up properly. - -| - -+ _ajax head template_ - -+ _ajax div template_ - -+ _ajax a template_ - - (ok) In addition to these templates, be familiar with the _ajax event system_ provided by the framework and Dojo. - -__ajax a template__ - - -The ajax theme is experimental. Feedback is appreciated. - -| - -The ajax a template is used to make asynchronous calls to the server when the user clicks on the a href link. It is useful when you need to communicate information back to the application from the UI, without requiring the entire page to be re-rendered. An example would be removing an item from a list. - -The _preInvokeJS_ attribute is used to determine whether the URL specified should be called or not, and must contain Javascript that returns _true_ or _false_ . If you want to call a JavaScript function, use the format preInvokeJS='yourMethodName(data,type)'. An example would be to show a confirm dialog to the user to double check whether they want to remove a user from a list. - -**Remember**: the content returned by the _href_ attribute must be JavaScript. That JavaScript will then be evaluated within the webpage. If you only wish to publish an event to the topic specified, then simply return no result (or NONE) from your action and utilize the _notifyTopics_ attribute to specific the topic names. - -For an example of the interaction between the [div](#PAGE_13908) tag and the [a](#PAGE_14027) tag using the topic pub/sub model, see the examples in the _ajax div template_ . - -__ajax div template__ - - -The Ajax theme is experimental. Feedback is appreciated. - -| - -The ajax [div](#PAGE_13908) template provides a much more interesting div rendering option that the other themes do. Rather than simply rendering a - -~~~~~~~ -<div> -~~~~~~~ - tag, this template relies on advanced AJAX features provided by the [Dojo Toolkit](http://dojotoolkit.org)^[http://dojotoolkit.org]. While the [div](#PAGE_13908) tag could be used outside of the [ajax theme](#PAGE_14205), it is usually not very useful. See the [div](#PAGE_13908) tag for more information on what features are provided. - -__Features__ - -The remote div has a few features, some of which can be combined with the [a](#PAGE_14027) tag and the _ajax a template_ . These uses are: - -+ Retrieve remote data - -+ Initialize the div with content before the remote data is retrieved - -+ Display appropriate error and loading messages - -+ Refresh data on a timed cycle - -+ Listen for events and refresh data - -+ JavaScript control support - -__Retrieve Remote Data__ - -The simplest way to use the div tag is to provide an _href_ attribute. For example: - - -~~~~~~~ - -<saf:div theme="ajax" id="weather" href="http://www.weather.com/weather?zip=97239"/> - -~~~~~~~ - -What this does after the HTML page is completely loaded, the specified URL will be retrieved asynchronously in the browser. The entire contents returned by that URL will be injected in to the div. - -__Initializing the Div__ - -Because the remote data isn't loaded immediately, it is sometimes useful to have some placeholder content that exists before the remote data is retrieved. The content is essentially just the body of the div element. For example: - - -~~~~~~~ - -<saf:div theme="ajax" id="weather" href="http://www.weather.com/weather?zip=97239"> - Placeholder... -</saf:div> - -~~~~~~~ - -If you wish to load more complex initial data, you can use the [action](#PAGE_14034) tag and the _executeResult_ attribute: - - -~~~~~~~ - -<saf:div theme="ajax" id="weather" href="http://www.weather.com/weather?zip=97239"> - <ww:action id="weather" name="weatherBean" executeResult="true"> - <ww:param name="zip" value="97239"/> - </ww:action> -</saf:div> - -~~~~~~~ - -__Loading and Error Messages__ - -If you'd like to display special messages when the data is being retrieved or when the data cannot be retrieved, you can use the _errorText_ and _loadingText_ attributes: - - -~~~~~~~ - -<saf:div theme="ajax" id="weather" href="http://www.weather.com/weather?zip=97239" - loadingText="Loading weather information..." - errorText="Unable to contact weather server"> - Placeholder... -</saf:div> - -~~~~~~~ - -__Refresh Timers__ - -Another feature this div template provides is the ability to refresh data on a timed basis. Using the _updateFreq_ and the _delay_ attributes, you can specify how often the timer goes off and when the timer starts (times in milliseconds). For example, the following will update every minute after a two second delay: - - -~~~~~~~ - -<saf:div theme="ajax" id="weather" href="http://www.weather.com/weather?zip=97239" - loadingText="Loading weather information..." - errorText="Unable to contact weather server"> - delay="2000" - updateFreq="60000" - Placeholder... -</saf:div> - -~~~~~~~ - -__Listening for Events__ - -The [a](#PAGE_14027) tag (specifically the _ajax a template_ ) and the div tag support an _ajax event system_ , providing the ability to broadcast events to topics. You can specify the **topics** to listen to using a comma separated list in the _listenTopics_ attribute. What this means is that when a topic is published, usually through the _ajax a template_ , the URL specified in the _href_ attribute will be re-requested. - - -~~~~~~~ - -<saf:div theme="ajax" id="weather" href="http://www.weather.com/weather?zip=97239" - loadingText="Loading weather information..." - errorText="Unable to contact weather server" - listenTopics="weather_topic,some_topic"> - Placeholder... -</saf:div> -<saf:a id="link1" - theme="ajax" - href="refreshWeather.action" - notifyTopics="weather_topic,other_topic" - errorText="An Error ocurred">Refresh</saf:a> - -~~~~~~~ - -__JavaScript Support__ - -There are also javascript functions to refresh the content and stop/start the refreshing of the component. For the remote div with the component id "remotediv1": - -To start refreshing use the javascript: - - -~~~~~~~ - -remotediv1.startTimer(); - -~~~~~~~ - -To stop refreshing use the javascript: - - -~~~~~~~ - -remotediv1.stopTimer(); - -~~~~~~~ - -To refresh the content use the javascript: - - -~~~~~~~ - -remotediv1.refresh(); - -~~~~~~~ - -__JavaScript Examples:__ - -To further illustrate these concepts here is an example. Say you want to change the url of a div at runtime via javascript. Here is what you need to do: - -What you will need to do is add a JS function that listens to a JS event that publishes the id from the select box that was selected. It will modify the URL for the div (adding the id so the correct data is obtained) and then bind() the AJAX div so it refreshes. - - -~~~~~~~ - -<saf:head theme="ajax" /> - -<script type="text/javascript"> - function updateReports(id) { - var reportDiv= window['reportDivId']; - reportDiv.href = '/../reportListRemote.action?selectedId='+id; - reportDiv.refresh(); - } - dojo.event.topic.getTopic("updateReportsListTopic").subscribe(null, "updateReports"); -</script> - -<form ... > -<saf:select .... onchange="javascript: dojo.event.topic.publish("updateReportsListTopic", this.value); " /> - -<saf:div id="reportDivId" theme="ajax" href="/.../reportListRemote.action" > - Loading reports... -</saf:div> -</form> - -~~~~~~~ - -__ajax event system__ - -As you may have seen with the _ajax div template_ and _ajax a template_ , the framework and Dojo provide a nice way to subscribe and notify of topics from within the browser. A benifit of using Dojo as the basis of many of these components is being able to loosely couple UI components. There are two attributes of importance: - -~~~~~~~ -listenTopics -~~~~~~~ - and - -~~~~~~~ -notifyTopics -~~~~~~~ -. - -+ If a component has a - -~~~~~~~ -notifyTopics -~~~~~~~ - attribute, then after the processing has been completed a message with be published to the topic names supplied as a value (comma delimited). - -+ If a component has a - -~~~~~~~ -listenTopics -~~~~~~~ - attribute, then when a message is published to the topic names supplied as a value (comma delimited), the component will perform custom tag-specific logic ( i.e a DIV tag will re-fresh its content). - -As well as this, you can publish and subscribe to topic names with javascript code. To publish to the - -~~~~~~~ -topic_name -~~~~~~~ - topic: - - -~~~~~~~ - -dojo.event.topic.publish("topic_name", "content"); - -~~~~~~~ - -The topic_name attribute is required, the content attribute is not and most elements are triggered without having this attribute. See the _ajax div template_ for an example of this type of interaction. - -To subscribe to the _topic_name_ topic: - - -~~~~~~~ - -function doSomethingWithEvent(data) { -... -} - -dojo.event.topic.getTopic("topic_name").subscribe(null, "doSomethingWithEvent"); - -~~~~~~~ - -The - -~~~~~~~ -subscribe -~~~~~~~ - method takes 2 parameters, the first is the JavaScript object variable (or null if the function is not from an object) and the second is the name of the function to call when an event is recieved on the topic. - -__ajax head template__ - -The ajax [head](#PAGE_13997) template builds upon the _xhtml head template_ by providing additional JavaScript includes for the [Dojo Toolkit](http://dojotoolkit.org)^[http://dojotoolkit.org], which is used by the _ajax a template_ , _ajax div template_ , and the _ajax tabbedPanel template_ . It is required to use this tag, - -~~~~~~~ -<ww:head theme="ajax"/> -~~~~~~~ -, in your HTML - -~~~~~~~ -<head> -~~~~~~~ - block if you wish to use AJAX feature. The contents of **head.ftl** are: - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/plugins/dojo/src/main/resources/template/ajax/head.ftl} -~~~~~~~ - - - -| If you are having trouble getting the AJAX theme to work, you should include the above JavaScript in your page manually, changing "isDebug: false" to "isDebug: true". This will log out debugging information directly to the screen. - -| - -Note that Dojo is configured to use the same character encoding specified in _struts.properties_ , typically UTF-8. For a simple example of how to use the [head](#PAGE_13997) tag with the AJAX theme, simply do the following in your HTML: - - -~~~~~~~ -{snippet:id=common-include|lang=xml|url=struts2/apps/showcase/src/main/webapp/ajax/commonInclude.jsp} -~~~~~~~ - - -> - -> - -> The above sample is from Struts trunk; for 2.0.6 you should use <s:head debug="true"/>. - -> +The header provides for [AJAX Client Side Validation](../core-developers/ajax-client-side-validation.html) by checking +if the `validate` attribute is set to true. If it is, a validation request is made on each `onblur` event +for a HTML [Struts Tags](struts-tags.html). Some people don't like the `onblur` behavior; they would rather a more +advanced timer (say, 200ms) be kicked off after every keystroke. You can override this template and provide that +type of behavior if you would like. -__ajax tabbedPanel template__ +## Special Interest -TODO: Describe the Ajax TabbedPanel template +Three ajax_xhtml templates of special interest are `head`, `div` , and `a`. -__ajax submit template__ +> Especially with the ajax theme, it is important to use the [head](dojo-head-tag.html) tag. +> (See the [ajax head template](ajax-head-template.html) for more information.) Without it, AJAX support may not be set +> up properly. -TODO: Describe the Ajax Submit template +- [ajax head template](ajax-head-template.html) +- [ajax div template](ajax-div-template.html) +- [ajax a template](ajax-a-template.html) +> In addition to these templates, be familiar with the [ajax event system](ajax-event-system.html) provided by +> the framework and Dojo. diff --git a/source/tag-developers/css-xhtml-theme.md b/source/tag-developers/css-xhtml-theme.md index eabf779..3ab52a1 100644 --- a/source/tag-developers/css-xhtml-theme.md +++ b/source/tag-developers/css-xhtml-theme.md @@ -5,145 +5,76 @@ title: Tag Developers Guide (WIP) # css_xhtml theme -The css_xhtml theme provides all the basics that the [simple theme](#PAGE_14291) provides and adds several features. +The _css_xhtml theme_ provides all the basics that the [simple theme](simple-theme.html) provides and adds several features. -+ Standard two-column CSS-based layout, using +_ Standard two-column CSS-based layout, using `<div>` for the HTML [Struts Tags](struts-tags.html) ([form](form-tag.htmk), + [textfield](textfield-tag.html), [select](select-tag.html), etc) +- Labels for each of the HTML [Struts Tags](struts-tags.html), placed according to the CSS stylesheet +- [Validation](../core-developers/validation.html) and error reporting +- [Pure JavaScript Client Side Validation](../core-developers/pure-java-script-client-side-validation.html) using 100% + JavaScript on the browser -~~~~~~~ -<div> -~~~~~~~ - for the HTML [Struts Tags](#PAGE_14248) ([form](#PAGE_14201), [textfield](#PAGE_13912), [select](#PAGE_14127), etc) +## Wrapping the Simple Theme -+ Labels for each of the HTML [Struts Tags](#PAGE_14248), placed according to the CSS stylesheet +The xhtml theme uses the "wrapping" technique described by [Extending Themes](extending-themes.html). Let's look at how +the HTML tags are wrapped by a standard header and footer. For example, in the [textfield](textfield-tag.html) template, +`text.ftl`, the `controlheader.ftl` and `controlfooter.ftl` templates are wrapped around the simple template. -+ _Validation_ and error reporting +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/simple/text.ftl %} +{% endhighlight %} -+ _Pure JavaScript Client Side Validation_ using 100% JavaScript on the browser +## CSS XHTML theme header -__Wrapping the Simple Theme__ +The header used by the HTML tags in the css_xhtml theme is complicated. Unlike the [xhtml theme](xhtml-theme.html), +the CSS theme does not use a `labelposition` attribute. Instead, the label position is defined by CSS rules. -The xhtml theme uses the "wrapping" technique described by [Extending Themes](#PAGE_13962). Let's look at how the HTML tags are wrapped by a standard header and footer. For example, in the [textfield](#PAGE_13912) template, +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/css_xhtml/controlheader.ftl %} +{% endhighlight %} -~~~~~~~ -text.ftl -~~~~~~~ -, the +Note that the `fieldErrors`, usually caused by [Validation](../core-developers/validation.html), are displayed in a `div` +block before the element is displayed. -~~~~~~~ -controlheader.ftl -~~~~~~~ - and +## CSS XHTML theme footer -~~~~~~~ -controlfooter.ftl -~~~~~~~ - templates are wrapped around the simple template. +And the `controlfooter.ftl` contents: +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/css_xhtml/controlfooter.ftl %} +{% endhighlight %} -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/simple/text.ftl} -~~~~~~~ +## Special Interest -__CSS XHTML theme header__ +Two css_xhtml templates of special interest are `head` and `form`. -The header used by the HTML tags in the css_xhtml theme is complicated. Unlike the [xhtml theme](#PAGE_13834), the CSS theme does not use a +### Head template -~~~~~~~ -labelposition -~~~~~~~ - attribute. Instead, the label position is defined by CSS rules. +The css_xhtml [head](head-tag.html) template is similar to the xhtml head template. The difference is that CSS is used +to provide the layout. The contents of **head.ftl** are: +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/css_xhtml/head.ftl %} +{% endhighlight %} -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/css_xhtml/controlheader.ftl} -~~~~~~~ +The head includes a style sheet. The contents of **styles.css** are: -Note that the +{% highlight css %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/css_xhtml/styles.css %} +{% endhighlight %} -~~~~~~~ -fieldErrors -~~~~~~~ -, usually caused by _Validation_ , are displayed in a +### Form template -~~~~~~~ -div -~~~~~~~ - block before the element is displayed. +The css_xhtml [form](form-tag.html) template is almost exactly like the _xhtml form template_ , including support for +[Pure JavaScript Client Side Validation](../core-developers/pure-java-script-client-side-validation.html). The difference +is that instead of printing out an opening and closing `<table>` element, there are no elements. Instead, the CSS rules +for the individual HTML tags are assumed to handle all display logic. However, as noted, client-side validation is still +supported. -__CSS XHTML theme footer__ +### css_xhtml form template -And the - -~~~~~~~ -controlfooter.ftl -~~~~~~~ - contents: - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/css_xhtml/controlfooter.ftl} -~~~~~~~ - -__Special Interest__ - -Two css_xhtml templates of special interest are - -~~~~~~~ -head -~~~~~~~ - and - -~~~~~~~ -form -~~~~~~~ -. - -__Head template__ - -The css_xhtml [head](#PAGE_13997) template is similar to the xhtml head template. The difference is that CSS is used to provide the layout. - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/css_xhtml/head.ftl} -~~~~~~~ - -The head includes a style sheet. - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/css_xhtml/styles.css} -~~~~~~~ - -__Form template__ - -The css_xhtml [form](#PAGE_14201) template is almost exactly like the _xhtml form template_ , including support for _Pure JavaScript Client Side Validation_ . The difference is that instead of printing out an opening and closing - -~~~~~~~ -<table> -~~~~~~~ - element, there are no elements. Instead, the CSS rules for the individual HTML tags are assumed to handle all display logic. However, as noted, client-side validation is still supported. - -__css_xhtml form template__ - -The css_xhtml [form](#PAGE_14201) template is almost exactly like the _xhtml form template_ , including support for _Pure JavaScript Client Side Validation_ . The only difference is that instead of printing out an opening and closing - -~~~~~~~ -<table> -~~~~~~~ - element, there are no elements. Instead, the CSS rules for the individual HTML tags are assumed to handle all dislay logic. However, as noted, client side validation is still supported. - -__css_xhtml head template__ - -The css_xhtml [head](#PAGE_13997) template is very similar to the _xhtml head template_ . The only difference is that CSS that is included is specifically designed to provide the layout for the [css_xhtml theme](#PAGE_14215). The contents of **head.ftl** are: - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/css_xhtml/head.ftl} -~~~~~~~ - -The contents of **styles.css** are: - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/css_xhtml/styles.css} -~~~~~~~ +The css_xhtml [form](form-tag.html) template is almost exactly like the _xhtml form template_ , including support for +[Pure JavaScript Client Side Validation](../core-developers/pure-java-script-client-side-validation.html). The only +difference is that instead of printing out an opening and closing `<table>` element, there are no elements. Instead, +the CSS rules for the individual HTML tags are assumed to handle all display logic. However, as noted, client side +validation is still supported. diff --git a/source/tag-developers/simple-theme.md b/source/tag-developers/simple-theme.md index 866e473..e7e756b 100644 --- a/source/tag-developers/simple-theme.md +++ b/source/tag-developers/simple-theme.md @@ -4,34 +4,32 @@ title: Tag Developers Guide (WIP) --- # simple theme +{:.no_toc} -The simple theme renders "bare bones" HTML elements. The simple theme is most often used as a starting point for other themes. (See [Extending Themes](#PAGE_13962) for more.) +* Will be replaced with the ToC, excluding a header +{:toc} -For example, the [textfield](#PAGE_13912) tag renders the HTML +The simple theme renders "bare bones" HTML elements. The simple theme is most often used as a starting point for other +themes. (See [Extending Themes](extending-themes.html) for more.) -~~~~~~~ -<input/> -~~~~~~~ - tag without a label, validation, error reporting, or any other formatting or functionality. +For example, the [textfield](textfield-tag.html) tag renders the HTML `<input/>` tag without a label, validation, error +reporting, or any other formatting or functionality. +> Both the [xhtml theme](xhtml-theme.html) and [css_xhtml theme](css-xhtml-theme.xhtml) extend the simple theme. Look +> to them for examples of how to build on the foundation laid by the simple theme. +## Head Tag -| Both the [xhtml theme](#PAGE_13834) and [css_xhtml theme](#PAGE_14215) extend the simple theme. Look to them for examples of how to build on the foundation laid by the simple theme. +The simple theme [head](head-tag.html) template prints out a javascript include required +for the [datetimepicker](dojo-datetimepicker-tag.html) tag to render properly. -| +## simple head template -__Head Tag__ +The [simple theme](simple-theme.html)[head](head-tag.html) template only does one thing: it loads the minimal +Ajax/Dojo support so that tags can import Dojo widgets easily. -The simple theme [head](#PAGE_13997) template prints out a javascript include required for the [datetimepicker](#PAGE_14274) tag to render properly. - -__simple head template__ - -The [simple theme](#PAGE_14291)[head](#PAGE_13997) template only does one thing: it loads the minimal Ajax/Dojo support so that tags can import Dojo widgets easily. - -The source of the simple head.ftl template is: - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/simple/head.ftl} -~~~~~~~ +The source of the simple `head.ftl` template is: +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/simple/head.ftl %} +{% endhighlight %} diff --git a/source/tag-developers/xhtml-theme.md b/source/tag-developers/xhtml-theme.md index fcd954e..071beb3 100644 --- a/source/tag-developers/xhtml-theme.md +++ b/source/tag-developers/xhtml-theme.md @@ -4,211 +4,119 @@ title: Tag Developers Guide (WIP) --- # xhtml theme +{:.no_toc} -The xhtml provides all the basics that the [simple theme](#PAGE_14291) provides and adds several features. +* Will be replaced with the ToC, excluding a header +{:toc} -+ Standard two-column table layout for the HTML [Struts Tags](#PAGE_14248) ([form](#PAGE_14201), [textfield](#PAGE_13912), [select](#PAGE_14127), and so forth) +The xhtml provides all the basics that the [simple theme](simple-theme.html) provides and adds several features. -+ Labels for each of the HTML [Struts Tags](#PAGE_14248) on the left hand side (or top, depending on the +- Standard two-column table layout for the HTML [Struts Tags](struts-tags.html) ([form](form-tag.html), + [textfield](textfield-tag.html), [select](select-tag.html), and so forth) +- Labels for each of the HTML [Struts Tags](struts-tags.html) on the left hand side (or top, depending on + the `labelposition` attribute) +- [Validation](../core-developers/validation.html) and error reporting +- [Pure JavaScript Client Side Validation](../core-developers/pure-java-script-client-side-validation.html) using + 100% JavaScript on the browser -~~~~~~~ -labelposition -~~~~~~~ - attribute) +## Wrapping the Simple Theme -+ _Validation_ and error reporting +The xhtml theme uses the "wrapping" technique described by [Extending Themes](extending-themes.html). Let's look at how +the HTML tags are wrapped by a standard header and footer. For example, in the `text.ftl` template, the `controlheader.ftl` +and `controlfooter.ftl` templates are wrapped around the simple template. -+ _Pure JavaScript Client Side Validation_ using 100% JavaScript on the browser +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/xhtml/text.ftl %} +{% endhighlight %} -__Wrapping the Simple Theme__ +> The `controlheader.ftl` is referenced using `${parameters.theme}` so that the code can be reused +> by the [ajax theme](ajax-theme.html). -The xhtml theme uses the "wrapping" technique described by [Extending Themes](#PAGE_13962). Let's look at how the HTML tags are wrapped by a standard header and footer. For example, in the +## XHTML Theme Header -~~~~~~~ -text.ftl -~~~~~~~ - template, the +Now let's look at the `controlheader.ftl` and `controlheader-core.ftl`. Again, these are split up for easy re-use with +the [ajax theme](ajax-theme.html)) contents: -~~~~~~~ -controlheader.ftl -~~~~~~~ - and +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/xhtml/controlheader.ftl %} +{% endhighlight %} -~~~~~~~ -controlfooter.ftl -~~~~~~~ - templates are wrapped around the simple template. +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/xhtml/controlheader-core.ftl %} +{% endhighlight %} +The header used by the HTML tags in the xhtml theme is complicated. However, a close look reveals that the logic produces +two behaviors: either a two-column format or a two-row format. Generally the two-column approach is what we want, so that +is the default option. To use the two-row approach, change the `labelposition` parameter to `top`. -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/xhtml/text.ftl} -~~~~~~~ +> The `fieldErrors`, usually caused by [Validation](../core-developers/validation.html), are printed out as a row above +> the HTML form element. Some people prefer that the errors display elsewhere, such as in a third column. If you wish +> to place these elsehwere, overriding the headers is easy, allowing you to continue to use the other features provided +> by this theme. See [Template Loading](template-loading.html) for more information on how to do this. - (?) The +## XHTML Theme Footer -~~~~~~~ -controlheader.ftl -~~~~~~~ - is referenced using \${parameters.theme} so that the code can be reused by the [ajax theme](#PAGE_14205). +The primary objective of `controlfooter.ftl` is to close the table. But, before the table closes, the template checks +for an `after` parameter. -__XHTML Theme Header__ +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/xhtml/controlfooter.ftl %} +{% endhighlight %} -Now let's look at the +While `after` isn't an attribute supported by any of the [Struts Tags](struts-tags.html), if you are using +[FreeMarker Tags](freemarker-tags.html), [Velocity Tags](velocity-tags.html), or the [param](param-tag.html) tag in any +template language, you can add an `after` parameter to place any content you like after the [simple theme](simple-theme.html) +template renders. The `after` attribute makes it easier to fine-tune HTML forms for your specific environment. -~~~~~~~ -controlheader.ftl -~~~~~~~ - and +## Special Interest -~~~~~~~ -controlheader-core.ftl -~~~~~~~ -. Again, these are split up for easy re-use with the [ajax theme](#PAGE_14205)) contents: +Two xhtml templates of special interest are `head` and `form`. +### xhtml head template -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/xhtml/controlheader.ftl} -~~~~~~~ +The xhtml [head](head-tag.html) template extends the _simple head template_ and provides an additional CSS that helps +render the form elements. +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/xhtml/head.ftl %} +{% endhighlight %} -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/xhtml/controlheader-core.ftl} -~~~~~~~ +The head template imports a style sheet. The contents of **styles.css** are: -The header used by the HTML tags in the xhtml theme is complicated. However, a close look reveals that the logic produces two behaviors: either a two-column format or a two-row format. Generally the two-column approach is what we want, so that is the default option. To use the two-row approach, change the +{% highlight css %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/xhtml/styles.css %} +{% endhighlight %} -~~~~~~~ -labelposition -~~~~~~~ - parameter to +### form template -~~~~~~~ -top -~~~~~~~ -. +The xhtml form template sets up the wrapping table around all the other form elements. In addition to creating this +wrapping table, the opening and closing templates also, if the `validate` parameter is set to true, enable +[Pure JavaScript Client Side Validation](../core-developers/pure-java-script-client-side-validation.html). +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/xhtml/form.ftl %} +{% endhighlight %} +The closing template, `form-close.ftl`: -| The fieldErrors, usually caused by _Validation_ , are printed out as a row above the HTML form element. Some people prefer that the errors display elsewhere, such as in a third column. If you wish to place these elsehwere, overriding the headers is easy, allowing you to continue to use the other features provided by this theme. See [Template Loading](#PAGE_13817) for more information on how to do this. +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/xhtml/form-close.ftl %} +{% endhighlight %} -| +### xhtml form template -__XHTML Theme Footer__ +The xhtml form template sets up the wrapping table around all the other [xhtml theme](xhtml-theme.html) form elements. +In addition to creating this wrapping table, the opening and closing templates also, if the `validate` parameter is set +to `true`, enable [Pure JavaScript Client Side Validation](../core-developers/pure-java-script-client-side-validation.htmk). -The primary objective of +See the **form.ftl** contents: -~~~~~~~ -controlfooter.ftl -~~~~~~~ - is to close the table. But, before the table closes, the template checks for an - -~~~~~~~ -after -~~~~~~~ - parameter. - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/xhtml/controlfooter.ftl} -~~~~~~~ - -While "after" isn't an attribute supported by any of the [Struts Tags](#PAGE_14248), if you are using [FreeMarker Tags](#PAGE_14294), [Velocity Tags](#PAGE_13950), or the [param](#PAGE_13825) tag in any template language, you can add an - -~~~~~~~ -after -~~~~~~~ - parameter to place any content you like after the [simple theme](#PAGE_14291) template renders. The - -~~~~~~~ -after -~~~~~~~ - attribute makes it easier to fine-tune HTML forms for your specific environment. - -__Special Interest__ - -Two xhtml templates of special interest are - -~~~~~~~ -head -~~~~~~~ - and - -~~~~~~~ -form -~~~~~~~ -. - -__head template__ - -The xhtml [head](#PAGE_13997) template extends the _simple head template_ and provides an additional CSS that helps render the form elements. - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/xhtml/head.ftl} -~~~~~~~ - -The head template imports a style sheet. - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/xhtml/styles.css} -~~~~~~~ - -__form template__ - -The xhtml form template sets up the wrapping table around all the other form elements. In addition to creating this wrapping table, the opening and closing templates also, if the - -~~~~~~~ -validate -~~~~~~~ - parameter is set to true, enable _Pure JavaScript Client Side Validation_ . - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/xhtml/form.ftl} -~~~~~~~ - -The closing template, - -~~~~~~~ -form-close.ftl* -~~~~~~~ -: - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/xhtml/form-close.ftl} -~~~~~~~ - -__xhtml form template__ - -The xhtml form template sets up the wrapping table around all the other [xhtml theme](#PAGE_13834) form elements. In addition to creating this wrapping table, the opening and closing templates also, if the _validate_ parameter is set to true, enable _Pure JavaScript Client Side Validation_ . See the **form.ftl** contents: - - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/xhtml/form.ftl} -~~~~~~~ +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/xhtml/form.ftl %} +{% endhighlight %} The closing template, **form-close.ftl**: - -~~~~~~~ -{snippet:id=all|lang=xml|url=struts2/core/src/main/resources/template/xhtml/form-close.ftl} -~~~~~~~ - -__xhtml head template__ - -The xhtml [head](#PAGE_13997) template extends the _simple head template_ and provides an additional CSS that helps render the [xhtml theme](#PAGE_13834) form elements. The contents of **head.ftl** are: - - -~~~~~~~ -{snippet:id=all|lang=xml|url=webwork/src/java/template/xhtml/head.ftl} -~~~~~~~ - -The contents of **styles.css** are: - - -~~~~~~~ -{snippet:id=all|lang=xml|url=webwork/src/java/template/xhtml/styles.css} -~~~~~~~ - +{% highlight freemarker %} +{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/main/resources/template/xhtml/form-close.ftl %} +{% endhighlight %} -- To stop receiving notification emails like this one, please contact ['"commits@struts.apache.org" <commits@struts.apache.org>'].