http://git-wip-us.apache.org/repos/asf/struts-site/blob/124e36c4/content/docs/freemarker-tags.html ---------------------------------------------------------------------- diff --git a/content/docs/freemarker-tags.html b/content/docs/freemarker-tags.html new file mode 100644 index 0000000..86fa41c --- /dev/null +++ b/content/docs/freemarker-tags.html @@ -0,0 +1,265 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> + <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> + <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushCss.js' type='text/javascript'></script> + <script type="text/javascript"> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); + </script> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>FreeMarker Tags</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="tag-developers-guide.html">Tag Developers Guide</a> > <a href="freemarker-tags.html">FreeMarker Tags</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="https://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">FreeMarker Tags</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14294"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14294">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14294"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14294">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14294"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14294">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><p>FreeMarker tags are extensions of the generic <a shape="rect" href="struts-tags.html">Struts Tags</a> provided by the framework. You can jump right in just by knowing the generic structure in which the tags can be accessed: <code><@s.tag> ...</@s.tag></code>, where <em>tag</em> is any of the <a shape="rect" href="struts-tags.html">tags</a> supported by the framework.</p> + +<p>For example, in JSP you might create a form using Struts tags.</p> + +<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>JSP Form</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> +<s:form action="updatePerson"> + <s:textfield label="First name" name="firstName"/> + <s:submit value="Update"/> +</s:form> +</pre> +</div></div> + +<p>In FreeMarker the same form can also be built using Struts tags.</p> + +<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>FTL Form</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> +<@s.form action="updatePerson"> + <@s.textfield label="First name" name="firstName"/> + <@s.submit value="Update"/> +</@s.form> +</pre> +</div></div> +<p><em>But, wait there's more!</em></p> + +<p>Aside from doing everything that the JSP tags do, the FTL tags boast additional features that you can use to make your pages even easier to code. You can even invoke third-party JSP taglibs as if there were native FTL tags.</p> + +<h2 id="FreeMarkerTags-AttributesandParameters">Attributes and Parameters</h2> + +<p>Unlike older versions of JSP (in which the <a shape="rect" href="jsp-tags.html">JSP Tags</a> are based), FreeMarker allows for <em>dynamic attributes</em>, much like JSP 2.0. You can supply attributes to the tags that the tag doesn't explicitedly support. Those attributes that cannot be applied directly to the tag object will be set to the tag's general-purpose <code>parameters</code> Map.</p> + +<p>Suppose we wanted to build an URL in a JSP. The URL needs to take an arbitary parameter to the query string, that (being arbitary) isn't specified on the URL tag. In a JSP, we'd have to use the <code>url</code> and <code>param</code> tags together.</p> + +<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Creating a URL with a query string (JSP)</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> +<s:url value="somePage"> + <s:param name="personId" value="%{personId}"/> +</s:url> +</pre> +</div></div> + +<p>In FreeMarker, we can pass the arbitrary parameter directly and create the URL in one simple statement.</p> + +<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Creating a URL with a query string (FTL)</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> +<@s.url value="somePage" personId="${personId}"/> +</pre> +</div></div> + +<h3 id="FreeMarkerTags-Usinginlineattributeswithtemplates">Using inline attributes with templates</h3> + +<p>Suppose you created a "three column" theme to replace the typical two column theme (xhtml). You might want an additional parameter to display in the third column called "description". Using FreeMarker, you can just pop the description attribute into the textfield tag, no fuss, no muss.</p> + +<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Passing an attribute to the template</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> +<@s.form action="updatePerson"> + <@s.textfield label="First name" name="firstName" description="..."/> + <@s.submit value="Update"/> +</@s.form> +</pre> +</div></div> + +<p>In the new template, the description is referenced via the parameters Map: "${parameters.description}".</p> + +<div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Advanced uses of the param tag</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"> +<p>For simple cases, inline attributes are much easier to use than the <code>param} tag. But, the {{param} tag is more flexible than inline attributes for advanced use cases. For example, {{param</code> can take the entire body of the tag and apply that as the <em>value</em> attribute.</p></div></div> + +<h2 id="FreeMarkerTags-AttributeTypes">Attribute Types</h2> + +<p>Remember that all tag attributes must first be set as Strings - they are then later evaluated (using <a shape="rect" href="ognl.html">OGNL</a>) to a different type, such as List, int, or boolean. This generally works just fine, but it can be limiting when using FreeMarker which provides more advanced ways to apply attributes. Suppose the following example:</p> +<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> +<@s.select label="Foo label - ${foo}" name="${name}" list="%{{1, 2, 3}}"/> +</pre> +</div></div> +<p>What will happen here is that each attribute will be evaluated to a String as best it can. This may involve calling the <code>toString</code> method on the internal FreeMarker objects. In this case, all objects will end up being exactly what you would expect. Then, when the tag runs, the <code>list</code> attribute will be converted from a String to a List using <a shape="rect" href="ognl.html">OGNL</a>'s advanced collection support.</p> + +<p>But suppose you wish to use FreeMarker's list or hash support instead? You can do this:</p> + +<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> +<@s.select label="Foo label - ${foo}" name="${name}" list=[1, 2, 3]/> +</pre> +</div></div> + +<p>Notice that the list attribute no longer has quotes around it. Now it will come in to the tag as an object that can't easily be converted to a String. Normally, the tag would just call <code>toString</code>, which would return "[1, 2, 3]" and be unable to be converted back to a List by OGNL. Rather than go through all this back and forth, the frameworks's FreeMarker tag support will recognize collections and not pass them through the normal tag attribute. Instead, the framework will set them directly in the <code>parameters</code> Map, ready to be consumed by the template.</p> + +<p>In the end, everything tends to do what you would expect, but it can help to understand the difference of when OGNL is being used and when it isn't, and how attribute types get converted.</p> + +<h2 id="FreeMarkerTags-JSPTagSupport">JSP Tag Support</h2> + +<p>While the framework provides native FreeMarker Tags, you might wish to use other third-party tags that are only available for JSP. Fortunately, FreeMarker has the ability to run JSP tags. To do so, you must include the JspSupportServlet in the application's <code>web.xml</code>, as this allows the FreeMarker integration to get access to the required objects needed to emulate a JSP taglib container.</p> + +<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Adding JspSupportSerlvet to web.xml</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> +<servlet> + <servlet-name>JspSupportServlet</servlet-name> + <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class> + <load-on-startup>1</load-on-startup> +</servlet> +</pre> +</div></div> + +<p>Once you've done that, you can simply add something like this in your templates:</p> + +<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> +<#assign cewolf=JspTaglibs["/WEB-INF/cewolf.tld"] /> +... +<@cewold.xxx ... /> +</pre> +</div></div> + +<h2 id="FreeMarkerTags-Next:">Next: <a shape="rect" href="velocity.html">Velocity</a></h2></div> + </div> + + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html>
http://git-wip-us.apache.org/repos/asf/struts-site/blob/124e36c4/content/docs/freemarker.html ---------------------------------------------------------------------- diff --git a/content/docs/freemarker.html b/content/docs/freemarker.html new file mode 100644 index 0000000..15d5676 --- /dev/null +++ b/content/docs/freemarker.html @@ -0,0 +1,249 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> + <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> + <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushCss.js' type='text/javascript'></script> + <script type="text/javascript"> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); + </script> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>FreeMarker</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="tag-developers-guide.html">Tag Developers Guide</a> > <a href="freemarker.html">FreeMarker</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="https://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">FreeMarker</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14078"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14078">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14078"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14078">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14078"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14078">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><p><style type="text/css">/*<![CDATA[*/ +div.rbtoc1499928275070 {padding: 0px;} +div.rbtoc1499928275070 ul {list-style: disc;margin-left: 0px;} +div.rbtoc1499928275070 li {margin-left: 0px;padding-left: 0px;} + +/*]]>*/</style></p><div class="toc-macro rbtoc1499928275070"> +<ul class="toc-indentation"><li><a shape="rect" href="#FreeMarker-GettingStarted">Getting Started</a></li><li><a shape="rect" href="#FreeMarker-Servlet/JSPScopedObjects">Servlet / JSP Scoped Objects</a> +<ul class="toc-indentation"><li><a shape="rect" href="#FreeMarker-ApplicationScopeAttribute">Application Scope Attribute</a></li><li><a shape="rect" href="#FreeMarker-SessionScopeAttribute">Session Scope Attribute</a></li><li><a shape="rect" href="#FreeMarker-RequestScopeAttribute">Request Scope Attribute</a></li><li><a shape="rect" href="#FreeMarker-RequestParameter">Request Parameter</a></li><li><a shape="rect" href="#FreeMarker-Contextparameter">Context parameter</a></li></ul> +</li><li><a shape="rect" href="#FreeMarker-TemplateLoading">Template Loading</a></li><li><a shape="rect" href="#FreeMarker-VariableResolution">Variable Resolution</a></li><li><a shape="rect" href="#FreeMarker-TagSupport">Tag Support</a></li><li><a shape="rect" href="#FreeMarker-TipsandTricks">Tips and Tricks</a> +<ul class="toc-indentation"><li><a shape="rect" href="#FreeMarker-TypeConversionandLocales">Type Conversion and Locales</a></li><li><a shape="rect" href="#FreeMarker-Extending">Extending</a></li><li><a shape="rect" href="#FreeMarker-ObjectWrapperSettings">ObjectWrapper Settings</a></li><li><a shape="rect" href="#FreeMarker-SyntaxNotes">Syntax Notes</a></li><li><a shape="rect" href="#FreeMarker-Cache">Cache</a></li><li><a shape="rect" href="#FreeMarker-IncompatibleImprovements">Incompatible Improvements</a></li></ul> +</li><li><a shape="rect" href="#FreeMarker-Next:">Next: FreeMarker Tags</a></li></ul> +</div><p>FreeMarker is a Java-based template engine that is a great alternative to <a shape="rect" href="jsp.html">JSP</a>. 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.</p><p>For more information on FreeMarker itself, please visit the <a shape="rect" class="external-link" href="http://freemarker.sourceforge.net/" rel="nofollow">FreeMarker website</a>.</p><div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The framework utilizes FreeMarker because the engine includes strong error reporting, built-in internationalization and p owerful macro libraries.</p><p>Support is also included for <a shape="rect" href="velocity.html">Velocity</a> templates. For a comparison of Velocity vs FreeMarker see <a shape="rect" class="external-link" href="http://freemarker.org/fmVsVel.html" rel="nofollow">here</a>.</p></div></div><h2 id="FreeMarker-GettingStarted">Getting Started</h2><p>Getting started with FreeMarker is as simple as ensuring all the dependencies are included in your project's classpath. Typically, the only dependency is <code>freemarker.jar</code>. Other than that, <a shape="rect" href="struts-defaultxml.html">struts-default.xml</a> already configures the <a shape="rect" href="freemarker-result.html">FreeMarker Result</a> needed to process your application's templates.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>struts.xml</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><action name="test" class="com.acme.TestAction"> + <result name="success" type="freemarker">test-success.ftl</result> +</action> +</pre> +</div></div><p>Then in <code>test-success.ftl</code>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>test-success.ftl</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><html> +<head> + <title>Hello</title> +</head> +<body> + +Hello, ${name} + +</body> +</html> +</pre> +</div></div><p>Where <code>name</code> is a property on your action. That's it! Read the rest of this document for details on how templates are loaded, variables are resolved, and tags can be used.</p><h2 id="FreeMarker-Servlet/JSPScopedObjects">Servlet / JSP Scoped Objects</h2><p>The following are ways to obtained Application scope attributes, Session scope attributes, Request scope attributes, Request parameters, and framework Context scope parameters:-</p><h3 id="FreeMarker-ApplicationScopeAttribute">Application Scope Attribute</h3><p>Assuming there's an attribute with name <code>myApplicationAttribute</code> in the Application scope.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"><#if Application.myApplicationAttribute?exists> + ${Application.myApplicationAttribute} +</#if> +</pre> +</div></div><p>or</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"><@s.property value="%{#application.myApplicationAttribute}" /> +</pre> +</div></div><h3 id="FreeMarker-SessionScopeAttribute">Session Scope Attribute</h3><p>Assuming there's an attribute with name <code>mySessionAttribute</code> in the Session scope.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"><#if Session.mySessionAttribute?exists> + ${Session.mySessionAttribute} +</#if> +</pre> +</div></div><p>or</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"><@s.property value="%{#session.mySessionAttribute}" /> +</pre> +</div></div><h3 id="FreeMarker-RequestScopeAttribute">Request Scope Attribute</h3><p>Assuming there's an attribute with name 'myRequestAttribute' in the Request scope.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"><#if Request.myRequestAttribute?exists> + ${Request.myRequestAttribute} +</#if> +</pre> +</div></div><p>or</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"><@s.property value="%{#request.myRequestAttribute}" /> +</pre> +</div></div><h3 id="FreeMarker-RequestParameter">Request Parameter</h3><p>Assuming there's a request parameter myParameter (eg. <a shape="rect" class="external-link" href="http://host/myApp/myAction.action?myParameter=one" rel="nofollow">http://host/myApp/myAction.action?myParameter=one</a>).</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"><#if Parameters.myParameter?exists> + ${Parameters.myParameter} +</#if> +</pre> +</div></div><p>or</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"><@s.property value="%{#parameters.myParameter}" /> +</pre> +</div></div><h3 id="FreeMarker-Contextparameter">Context parameter</h3><p>Assuming there's a parameter with the name myContextParam in framework context.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">${stack.findValue('#myContextParam')} +</pre> +</div></div><p>or</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"><@s.property value="%{#myContextParam}" /> +</pre> +</div></div><h2 id="FreeMarker-TemplateLoading">Template Loading</h2><p>The framework looks for FreeMarker templates in two locations (in this order):</p><ol><li>Web application</li><li>Class path</li></ol><p>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 <a shape="rect" href="form-tags.html">Form Tags</a> included with the framework.</p><p>In addition, you can specify a location (directory on your file system) through the <code>templatePath</code> or <code>TemplatePath</code> context variable (in the <code>web.xml</code>). If a variable is specified, the content of the directory it points to will be searched first.</p><div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="con fluence-information-macro-body"><p>This variable is currently NOT relative to the root of your application.</p></div></div><h2 id="FreeMarker-VariableResolution">Variable Resolution</h2><p>When using FreeMarker with the framework, variables are looked up in several different places, in this order:</p><ol><li>Built-in variables</li><li>Value stack</li><li>Action context</li><li>Request scope</li><li>Session scope</li><li>Application scope</li></ol><p>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 <code>s:property</code> tag. This is a nice convenience, though be careful because there is a small chance it could trip you up.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><@s.url id="url" value="http://www.yahoo.com"/> +Click <a xhref="${url}">here</a>! +</pre> +</div></div><p>The built-in variables that Struts-FreeMarker integration provides are:</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>stack</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The value stack itself, useful for calls like ${stack.findString('ognl expr')}</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>action</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The action most recently executed</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>response</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The HttpServletResponse</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>res</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Same as response</p></td></tr><tr ><td colspan="1" rowspan="1" class="confluenceTd"><p>request</p></td><td >colspan="1" rowspan="1" class="confluenceTd"><p>The >HttpServletRequest</p></td></tr><tr><td colspan="1" rowspan="1" >class="confluenceTd"><p>req</p></td><td colspan="1" rowspan="1" >class="confluenceTd"><p>Same as request</p></td></tr><tr><td colspan="1" >rowspan="1" class="confluenceTd"><p>session</p></td><td colspan="1" >rowspan="1" class="confluenceTd"><p>The HttpSession</p></td></tr><tr><td >colspan="1" rowspan="1" class="confluenceTd"><p>application</p></td><td >colspan="1" rowspan="1" class="confluenceTd"><p>The >ServletContext</p></td></tr><tr><td colspan="1" rowspan="1" >class="confluenceTd"><p>base</p></td><td colspan="1" rowspan="1" >class="confluenceTd"><p>The request's context >path</p></td></tr></tbody></table></div><h2 id="FreeMarker-TagSupport">Tag >Support</h2><p>FreeMarker includes complete tag support. See the <a >shape="rect" href="freemarker-tags.html">FreeMarker Tags</a> documentation >for information o n how to use the generic <a shape="rect" href="struts-tags.html">Struts Tags</a> provided by Struts. In addition to this, you can use any JSP tag, like so:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><#assign mytag=JspTaglibs["/WEB-INF/mytag.tld"]> +<@mytag.tagx attribute1="some ${value}"/> +</pre> +</div></div><p>Where <strong>mytag.tld</strong> is the JSP Tag Library Definition file for your tag library. Note: in order to use this support in FreeMarker, you must enable the <code>JSPSupportServlet</code> in <code>web.xml</code>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Adding JspSupportSerlvet to web.xml</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><servlet> + <servlet-name>JspSupportServlet</servlet-name> + <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class> + <load-on-startup>1</load-on-startup> +</servlet> +</pre> +</div></div><h2 id="FreeMarker-TipsandTricks">Tips and Tricks</h2><p>There are some advanced features that may be useful when building Struts applications with FreeMarker.</p><h3 id="FreeMarker-TypeConversionandLocales">Type Conversion and Locales</h3><p>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 <a shape="rect" href="strutsproperties.html">struts.properties</a> but can be over-ridden using the <a shape="rect" href="i18n-interceptor.html">I18n Interceptor</a>. 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 <a shape="rect" href="type-conversion.html">Type Conversion</a> support.</p><p>If you want the framework to handle the formatting according to the <a shape="rect" href="type-conversion.html">Type Conversion</a> you have specified, you shouldn't us e the normal ${...} syntax. Instead, you should use the <a shape="rect" href="property.html">property</a> tag. The difference is that the property tag is specifically designed to take an <a shape="rect" href="ognl.html">OGNL</a> expression, evaluate it, and then convert it to a String using any <a shape="rect" href="type-conversion.html">Type Conversion</a> 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.</p><p><img class="emoticon emoticon-warning" src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2a2.1/_/images/icons/emoticons/warning.png" data-emoticon-name="warning" alt="(warning)"> The difference in how type conversion is handled under Freemarker is subtle but important to understand.</p><h3 id="FreeMarker-Extending">Extending</h3><p>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.</p><p>To extend the Freemarker support, develop a class that extends <code>org.apache.struts2.views.freemarker.FreemarkerManager</code>, overriding methods as needed, and plugin the class through the <a shape="rect" href="strutsproperties.html">struts.properties</a>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<pre class="brush: plain; gutter: false; theme: Default" style="font-size:12px;">struts.freemarker.manager.classname = com.yourcompany.YourFreeMarkerManager +</pre> +</div></div><h3 id="FreeMarker-ObjectWrapperSettings">ObjectWrapper Settings</h3><p>Once you get familiar with FreeMarker, you will find certain <em>subtleties</em>with it that may become frustrating. The most common thing you'll likely run in to is the BeansWrapper provided by FreeMarker. If you don't know what this is, don't worry. However, if you do, know this:</p><p></p><p> +The StrutsBeanWrapper extends the default FreeMarker BeansWrapper and provides almost no change in functionality, +<b>except</b> for how it handles maps. Normally, FreeMarker has two modes of operation: either support for friendly +map built-ins (?keys, ?values, etc) but only support for String keys; OR no special built-in support (ie: ?keys +returns the methods on the map instead of the keys) but support for String and non-String keys alike. Struts +provides an alternative implementation that gives us the best of both worlds. +</p> + +<p></p><p> It is possible that this special behavior may be confusing or can cause problems. Therefore, you can set the +<b>struts.freemarker.wrapper.altMap</b> property in struts.properties to false, allowing the normal BeansWrapper +logic to take place instead. +</p><h3 id="FreeMarker-SyntaxNotes">Syntax Notes</h3><p>As of FreeMarker 2.3.4, an alternative syntax is supported. This alternative syntax is great if you find that your IDE (especially IntelliJ IDEA) makes it difficult to work with the default syntax. You can read more about this syntax <a shape="rect" class="external-link" href="http://freemarker.sourceforge.net/docs/dgui_misc_alternativesyntax.html" rel="nofollow">here</a>.</p><h3 id="FreeMarker-Cache">Cache</h3><p>You can enable FreeMarker cache mechanism by specifying below options in struts.xml:</p><ul><li><code><constant name="struts.freemarker.mru.max.strong.size" value="250" /></code> - this option will be used by <a shape="rect" class="external-link" href="http://freemarker.org/docs/api/freemarker/cache/MruCacheStorage.html" rel="nofollow">freemarker.cache.MruCacheStorage</a></li></ul><ul><li><code><constant name="struts.freemarker.templatesCache.updateDelay" value="1800" /></code> - default update cache inter val (5 seconds)</li></ul><ul><li><code><constant name="struts.freemarker.templatesCache" value="true" /></code> - *<strong>DEPRECATED</strong>* this option will use a internal ConcurrentHashMap in FreemarkerTemplateEngine but not freemarker native cache</li></ul><p>Setting <code>devMode</code> to true will disable cache and updateDelay immediately, but you can explicit specify these constants to enable cache even in <code>devMode</code>, see <a shape="rect" href="devmode.html">devMode</a></p><h3 id="FreeMarker-IncompatibleImprovements">Incompatible Improvements</h3><p>By default Struts is using FreeMarker in way to be backward compatible as much as possible but if you need to enable new features you can do it via <code>freemarker.properties</code> by defining <a shape="rect" class="external-link" href="http://freemarker.org/docs/pgui_config_incompatible_improvements.html#pgui_config_incompatible_improvements_how_to_set" rel="nofollow">incompatible improvements</a> se ttings, ie.:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>freemarker.properties</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">incompatible_improvements=2.3.22</pre> +</div></div><p>This can impact your freemarker powered pages and Struts tags as well, so please careful test this change.</p><h2 id="FreeMarker-Next:">Next: <a shape="rect" href="freemarker-tags.html">FreeMarker Tags</a></h2></div> + </div> + + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html> http://git-wip-us.apache.org/repos/asf/struts-site/blob/124e36c4/content/docs/generator.html ---------------------------------------------------------------------- diff --git a/content/docs/generator.html b/content/docs/generator.html new file mode 100644 index 0000000..3acfeff --- /dev/null +++ b/content/docs/generator.html @@ -0,0 +1,237 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> + <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> + <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushCss.js' type='text/javascript'></script> + <script type="text/javascript"> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); + </script> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>generator</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="tag-developers-guide.html">Tag Developers Guide</a> > <a href="struts-tags.html">Struts Tags</a> > <a href="tag-reference.html">Tag Reference</a> > <a href="generic-tag-reference.html">Generic Tag Reference</a> > <a href="generator.html">generator</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="https://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">generator</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=13883"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=13883">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=13883"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=13883">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=13883"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=13883">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><h2 id="generator-Description">Description</h2> + +<p><b>NOTE: JSP-TAG</b></p> + +<p></p><p>Generate an iterator based on the val attribute supplied.</p> + +<p><b>NOTE:</b> The generated iterator will <b>ALWAYS</b> be pushed into the top of the stack, and poped +at the end of the tag.</p> + +<h2 id="generator-Parameters">Parameters</h2> + +<p><table width="100%"><tr><td colspan="6" rowspan="1"><h4>Dynamic Attributes Allowed:</h4> false</td></tr><tr><td colspan="6" rowspan="1"> </td></tr><tr><th align="left" colspan="1" rowspan="1" valign="top"><h4>Name</h4></th><th align="left" colspan="1" rowspan="1" valign="top"><h4>Required</h4></th><th align="left" colspan="1" rowspan="1" valign="top"><h4>Default</h4></th><th align="left" colspan="1" rowspan="1" valign="top"><h4>Evaluated</h4></th><th align="left" colspan="1" rowspan="1" valign="top"><h4>Type</h4></th><th align="left" colspan="1" rowspan="1" valign="top"><h4>Description</h4></th></tr><tr><td align="left" colspan="1" rowspan="1" valign="top">converter</td><td align="left" colspan="1" rowspan="1" valign="top">false</td><td align="left" colspan="1" rowspan="1" valign="top"></td><td align="left" colspan="1" rowspan="1" valign="top">false</td><td align="left" colspan="1" rowspan="1" valign="top">org.apache.struts2.util.IteratorGenerator.Converter</td><td align="le ft" colspan="1" rowspan="1" valign="top">The converter to convert the String entry parsed from <i>val</i> into an object</td></tr><tr><td align="left" colspan="1" rowspan="1" valign="top">count</td><td align="left" colspan="1" rowspan="1" valign="top">false</td><td align="left" colspan="1" rowspan="1" valign="top"></td><td align="left" colspan="1" rowspan="1" valign="top">false</td><td align="left" colspan="1" rowspan="1" valign="top">Integer</td><td align="left" colspan="1" rowspan="1" valign="top">The max number entries to be in the iterator</td></tr><tr><td align="left" colspan="1" rowspan="1" valign="top">separator</td><td align="left" colspan="1" rowspan="1" valign="top"><strong>true</strong></td><td align="left" colspan="1" rowspan="1" valign="top"></td><td align="left" colspan="1" rowspan="1" valign="top">false</td><td align="left" colspan="1" rowspan="1" valign="top">String</td><td align="left" colspan="1" rowspan="1" valign="top">The separator to be used in separating the < i>val</i> into entries of the iterator</td></tr><tr><td align="left" colspan="1" rowspan="1" valign="top">val</td><td align="left" colspan="1" rowspan="1" valign="top"><strong>true</strong></td><td align="left" colspan="1" rowspan="1" valign="top"></td><td align="left" colspan="1" rowspan="1" valign="top">false</td><td align="left" colspan="1" rowspan="1" valign="top">String</td><td align="left" colspan="1" rowspan="1" valign="top">The source to be parsed into an iterator</td></tr><tr><td align="left" colspan="1" rowspan="1" valign="top">var</td><td align="left" colspan="1" rowspan="1" valign="top">false</td><td align="left" colspan="1" rowspan="1" valign="top"></td><td align="left" colspan="1" rowspan="1" valign="top">false</td><td align="left" colspan="1" rowspan="1" valign="top">String</td><td align="left" colspan="1" rowspan="1" valign="top">The name to store the resultant iterator into page context, if such name is supplied</td></tr></table></p> + +<h2 id="generator-Examples">Examples</h2> + +<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ +Example One: +<pre> +Generate a simple iterator +<s:generator val="%{'aaa,bbb,ccc,ddd,eee'}"> + <s:iterator> + <s:property /><br/> + </s:iterator> +</s:generator> +</pre> +This generates an iterator and print it out using the iterator tag. + +Example Two: +<pre> +Generate an iterator with count attribute +<s:generator val="%{'aaa,bbb,ccc,ddd,eee'}" count="3"> + <s:iterator> + <s:property /><br/> + </s:iterator> +</s:generator> +</pre> +This generates an iterator, but only 3 entries will be available in the iterator +generated, namely aaa, bbb and ccc respectively because count attribute is set to 3 + +Example Three: +<pre> +Generate an iterator with var attribute +<s:generator val="%{'aaa,bbb,ccc,ddd,eee'}" count="4" separator="," var="myAtt" /> +<% + Iterator i = (Iterator) pageContext.getAttribute("myAtt"); + while(i.hasNext()) { + String s = (String) i.next(); %> + <%=s%> <br/> +<% } +%> +</pre> +This generates an iterator and put it in the PageContext under the key as specified +by the var attribute. + + +Example Four: +<pre> +Generate an iterator with comparator attribute +<s:generator val="%{'aaa,bbb,ccc,ddd,eee'}" converter="%{myConverter}"> + <s:iterator> + <s:property /><br/> + </s:iterator> +</s:generator> + + +public class GeneratorTagAction extends ActionSupport { + + .... + + public Converter getMyConverter() { + return new Converter() { + public Object convert(String value) throws Exception { + return "converter-"+value; + } + }; + } + + ... + +} +</pre> +This will generate an iterator with each entries decided by the converter supplied. With +this converter, it simply add "converter-" to each entries. +]]></script> +</div></div></div> + </div> + + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html> http://git-wip-us.apache.org/repos/asf/struts-site/blob/124e36c4/content/docs/generic-tag-reference.html ---------------------------------------------------------------------- diff --git a/content/docs/generic-tag-reference.html b/content/docs/generic-tag-reference.html new file mode 100644 index 0000000..e96a338 --- /dev/null +++ b/content/docs/generic-tag-reference.html @@ -0,0 +1,223 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>Generic Tag Reference</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="tag-developers-guide.html">Tag Developers Guide</a> > <a href="struts-tags.html">Struts Tags</a> > <a href="tag-reference.html">Tag Reference</a> > <a href="generic-tag-reference.html">Generic Tag Reference</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="https://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">Generic Tag Reference</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=19735"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=19735">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=19735"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=19735">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=19735"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=19735">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><p> +</p><p>Struts Generic Tags control the execution flow as pages render.</p> + +<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Control Tags </p></th><td colspan="1" rowspan="1" class="confluenceTd"><ul><li><a shape="rect" href="if.html">if</a></li><li><a shape="rect" href="elseif.html">elseif</a></li><li><a shape="rect" href="else.html">else</a></li><li><a shape="rect" href="append.html">append</a></li><li><a shape="rect" href="generator.html">generator</a></li><li><a shape="rect" href="iterator.html">iterator</a></li><li><a shape="rect" href="merge.html">merge</a></li><li><a shape="rect" href="sort.html">sort</a></li><li><a shape="rect" href="subset.html">subset</a></li></ul> +</td><th colspan="1" rowspan="1" class="confluenceTh"><p> Data Tags </p></th><td colspan="1" rowspan="1" class="confluenceTd"><ul><li><a shape="rect" href="a.html">a</a></li><li><a shape="rect" href="action.html">action</a></li><li><a shape="rect" href="bean.html">bean</a></li><li><a shape="rect" href="date.html">date</a></li><li><a shape="rect" href="debug.html">debug</a></li><li><a shape="rect" href="i18n.html">i18n</a></li><li><a shape="rect" href="include.html">include</a></li><li><a shape="rect" href="param.html">param</a></li><li><a shape="rect" href="property.html">property</a></li><li><a shape="rect" href="push.html">push</a></li><li><a shape="rect" href="set.html">set</a></li><li><a shape="rect" href="text.html">text</a></li><li><a shape="rect" href="url.html">url</a></li></ul> +</td></tr></tbody></table></div> + +<h2 id="GenericTagReference-Next:">Next: <a shape="rect" href="ui-tags.html">UI Tags</a></h2></div> + </div> + + <div class="tabletitle"> + Children + <span class="smalltext" id="show" style="display: inline;"> + <a href="javascript:showChildren()">Show Children</a></span> + <span class="smalltext" id="hide" style="display: none;"> + <a href="javascript:hideChildren()">Hide Children</a></span> + </div> + <div class="greybox" id="children" style="display: none;"> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + </div> + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html> http://git-wip-us.apache.org/repos/asf/struts-site/blob/124e36c4/content/docs/generic-tags.html ---------------------------------------------------------------------- diff --git a/content/docs/generic-tags.html b/content/docs/generic-tags.html new file mode 100644 index 0000000..27a95c6 --- /dev/null +++ b/content/docs/generic-tags.html @@ -0,0 +1,144 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>Generic Tags</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="tag-developers-guide.html">Tag Developers Guide</a> > <a href="struts-tags.html">Struts Tags</a> > <a href="generic-tags.html">Generic Tags</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="https://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">Generic Tags</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=19745"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=19745">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=19745"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=19745">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=19745"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=19745">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><h2 id="GenericTags-GenericTags">Generic Tags</h2> + +<p>Generic tags are used for controlling the execution flow when the pages render. These tags also allow for data extraction from places other than your action or the value stack, such as <a shape="rect" href="localization.html">Localization</a>, JavaBeans, and including additional URLs or action executions.</p> +<ul><li>Control Tags provide control flow, such as <code>if</code>, <code>else</code>, and <code>iterator</code>.</li><li>Data Tags allow for data manipulation or creation, such as <code>bean</code>, <code>push</code>, and <code>i18n</code>.</li></ul> + + +<h2 id="GenericTags-Next">Next <a shape="rect" href="generic-tag-reference.html">Generic Tag Reference</a></h2></div> + </div> + + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html>