This is an automated email from the ASF dual-hosted git repository. git-site-role pushed a commit to branch asf-site in repository https://gitbox.apache.org/repos/asf/struts-site.git
The following commit(s) were added to refs/heads/asf-site by this push: new ba0d75a9b Automatic Site Publish by Buildbot ba0d75a9b is described below commit ba0d75a9bb466ba2388543987f65f045997e3d41 Author: buildbot <us...@infra.apache.org> AuthorDate: Sun May 28 07:14:38 2023 +0000 Automatic Site Publish by Buildbot --- output/tag-developers/ognl-basics.html | 98 +++++++--------------------------- output/tag-developers/ognl.html | 76 +++++++++++--------------- 2 files changed, 51 insertions(+), 123 deletions(-) diff --git a/output/tag-developers/ognl-basics.html b/output/tag-developers/ognl-basics.html index 9bd857119..4377ccd05 100644 --- a/output/tag-developers/ognl-basics.html +++ b/output/tag-developers/ognl-basics.html @@ -136,7 +136,6 @@ <ul id="markdown-toc"> <li><a href="#struts-specific-language-features" id="markdown-toc-struts-specific-language-features">Struts-specific language features</a> <ul> <li><a href="#accessing-static-properties" id="markdown-toc-accessing-static-properties">Accessing static properties</a></li> - <li><a href="#differences-from-the-webwork-1x-el" id="markdown-toc-differences-from-the-webwork-1x-el">Differences from the WebWork 1.x EL</a></li> <li><a href="#struts-2-named-objects" id="markdown-toc-struts-2-named-objects">Struts 2 Named Objects</a></li> </ul> </li> @@ -144,11 +143,11 @@ <h2 id="struts-specific-language-features">Struts-specific language features</h2> -<p>The biggest addition that Struts provides on top of OGNL is the support for the ValueStack. While OGNL operates under +<p>The biggest addition that Struts provides on top of OGNL is the support for the ValueStack. While OGNL operates under the assumption there is only one “root”, Struts’s ValueStack concept requires there be many “roots”.</p> -<p>For example, suppose we are using standard OGNL (not using Struts) and there are two objects in the OgnlContext map: -“foo” -> foo and “bar” -> bar and that the foo object is also configured to be the single <strong>root</strong> object. +<p>For example, suppose we are using standard OGNL (not using Struts) and there are two objects in the OgnlContext map: +“foo” -> foo and “bar” -> bar and that the foo object is also configured to be the single <strong>root</strong> object. The following code illustrates how OGNL deals with these three situations:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#foo.blah // returns foo.getBlah() @@ -156,34 +155,34 @@ The following code illustrates how OGNL deals with these three situations:</p> blah // returns foo.getBlah() because foo is the root </code></pre></div></div> -<p>What this means is that OGNL allows many objects in the context, but unless the object you are trying to access is the root, -it must be prepended with a namespaces such as @bar. Now let’s talk about how Struts is a little different…</p> +<p>What this means is that OGNL allows many objects in the context, but unless the object you are trying to access is the +root, it must be prepended with a namespaces such as @bar. Now let’s talk about how Struts is a little different…</p> <blockquote> - <p>In Struts, the entire ValueStack is the root object in the context. Rather than having your expressions get the object -you want from the stack and then get properties from that (ie: peek().blah), Struts has a special OGNL PropertyAccessor -that will automatically look at the all entries in the stack (from the top down) until it finds an object with the property -you are looking for.</p> + <p>In Struts, the entire ValueStack is the root object in the context. Rather than having your expressions get the object +you want from the stack and then get properties from that (ie: peek().blah), Struts has a special OGNL +PropertyAccessor that will automatically look at the all entries in the stack (from the top down) until it finds +an object with the property you are looking for.</p> </blockquote> -<p>For example, suppose the stack contains two objects: Animal and Person. Both objects have a “name” property, Animal has -a “species” property, and Person has a “salary” property. Animal is on the top of the stack, and Person is below it. -The follow code fragments help you get an idea of what is going on here:</p> +<p>For example, suppose the stack contains two objects: <code class="language-plaintext highlighter-rouge">Animal</code> and <code class="language-plaintext highlighter-rouge">Person</code>. Both objects have a <code class="language-plaintext highlighter-rouge">name</code> property, +<code class="language-plaintext highlighter-rouge">Animal</code> has a <code class="language-plaintext highlighter-rouge">species</code> property, and <code class="language-plaintext highlighter-rouge">Person</code> has a <code class="language-plaintext highlighter-rouge">salary</code> property. <code class="language-plaintext highlighter-rouge">Animal</code> is on the top of the stack, +and <code class="language-plaintext highlighter-rouge">Person</code> is below it. The follow code fragments help you get an idea of what is going on here:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>species // call to animal.getSpecies() salary // call to person.getSalary() name // call to animal.getName() because animal is on the top </code></pre></div></div> -<p>In the last example, there was a tie and so the animal’s name was returned. Usually this is the desired effect, but -sometimes you want the property of a lower-level object. To do this, XWork has added support for indexes on the ValueStack. -All you have to do is:</p> +<p>In the last example, there was a tie and so the animal’s name was returned. Usually this is the desired effect, but +sometimes you want the property of a lower-level object. To do this, XWork has added support for indexes on the +ValueStack. All you have to do is:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[0].name // call to animal.getName() [1].name // call to person.getName() </code></pre></div></div> -<p>With expression like <code class="language-plaintext highlighter-rouge">[0] ... [3]</code> etc. Struts will cut the stack and still return back a CompoundRoot object. To get +<p>With expression like <code class="language-plaintext highlighter-rouge">[0] ... [3]</code> etc. Struts will cut the stack and still return back a CompoundRoot object. To get the top of that particular stack cut, use <code class="language-plaintext highlighter-rouge">[0].top</code></p> <table> @@ -210,7 +209,8 @@ the top of that particular stack cut, use <code class="language-plaintext highli <p>OGNL supports accessing static properties as well as static methods.</p> <p>By default, Struts 2 is configured to disallow this - to enable OGNL’s static member support you must set the -<code class="language-plaintext highlighter-rouge">struts.ognl.allowStaticMethodAccess</code> constant to <code class="language-plaintext highlighter-rouge">true</code> via any of the <a href="../core-developers/constant-configuration">Constant Configuration</a> methods.</p> +<code class="language-plaintext highlighter-rouge">struts.ognl.allowStaticMethodAccess</code> constant to <code class="language-plaintext highlighter-rouge">true</code> via any +of the <a href="../core-developers/constant-configuration">Constant Configuration</a> methods.</p> <p>OGNL’s static access looks like this:</p> @@ -218,68 +218,10 @@ the top of that particular stack cut, use <code class="language-plaintext highli @some.package.ClassName@someMethod() </code></pre></div></div> -<p>However, Struts allows you to avoid having to specify the full package name and call static properties and methods of your -action classes using the “vs” prefix:</p> - -<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code><at:var at:name="vs" />FOO_PROPERTY -<at:var at:name="vs" />someMethod() - -<at:var at:name="vs1" />FOO_PROPERTY -<at:var at:name="vs1" />someMethod() - -<at:var at:name="vs2" />BAR_PROPERTY -<at:var at:name="vs2" />someOtherMethod() -</code></pre></div></div> - -<p>“vs” stands for “value stack”. The important thing to note here is that if the class name you specify is just “vs”, -the class for the object on the top of the stack is used. If you specify a number after the “vs” string, an object’s -class deeper in the stack is used instead.</p> - -<h3 id="differences-from-the-webwork-1x-el">Differences from the WebWork 1.x EL</h3> - -<p>Besides the examples and descriptions given above, there are a few major changes in the EL since WebWork 1.x. The biggest -one is that properties are no longer accessed with a forward slash (/) but with a dot (.). Also, rather than using “..” -to traverse down the stack, we now use “[n]” where n is some positive number. Lastly, in WebWork 1.x one could access -special named objects (the request scope attributes to be exact) by using “@foo”, but now special variables are accessed -using “#foo”. However, it is important to note that “#foo” does NOT access the request attributes. Because XWork is not -built only for the web, there is no concept of “request attributes”, and thus “#foo” is merely a request to another -object in the OgnlContext other than the root.</p> - -<table> - <thead> - <tr> - <th>Old Expression</th> - <th>New Expression</th> - </tr> - </thead> - <tbody> - <tr> - <td>foo/blah</td> - <td>foo.blah</td> - </tr> - <tr> - <td>foo/someMethod()</td> - <td>foo.someMethod()</td> - </tr> - <tr> - <td>../bar/blah</td> - <td>[1].bar.blah</td> - </tr> - <tr> - <td>@baz</td> - <td>not directly supported, but #baz is similar</td> - </tr> - <tr> - <td>.</td> - <td>‘top’ or [0]</td> - </tr> - </tbody> -</table> - <h3 id="struts-2-named-objects">Struts 2 Named Objects</h3> -<p>Struts 2 places request parameters and request, session, and application attributes on the OGNL stack. They may be accessed -as shown below.</p> +<p>Struts 2 places request parameters and request, session, and application attributes on the OGNL stack. They may be +accessed as shown below.</p> <table> <thead> diff --git a/output/tag-developers/ognl.html b/output/tag-developers/ognl.html index c58b932ce..ef02d29c8 100644 --- a/output/tag-developers/ognl.html +++ b/output/tag-developers/ognl.html @@ -134,11 +134,12 @@ <h1 class="no_toc" id="ognl">OGNL</h1> <ul id="markdown-toc"> + <li><a href="#context" id="markdown-toc-context">Context</a></li> + <li><a href="#referencing-an-action-property" id="markdown-toc-referencing-an-action-property">Referencing an Action property</a></li> <li><a href="#collections-maps-lists-sets" id="markdown-toc-collections-maps-lists-sets">Collections (Maps, Lists, Sets)</a></li> - <li><a href="#lambda-expressions" id="markdown-toc-lambda-expressions">Lambda Expressions</a></li> </ul> -<p>OGNL is the Object Graph Navigation Language (see [http://commons.apache.org/proper/commons-ognl/] for the full +<p>OGNL is the Object Graph Navigation Language (see <a href="https://ognl.orphan.software/">OGNL page</a> for the full documentation of OGNL). Here, we will cover a few examples of OGNL features that co-exist with the framework. To review basic concepts, refer to <a href="ognl-basics">OGNL Basics</a>.</p> @@ -147,10 +148,12 @@ a Map (usually referred as a context map or context). OGNL has a notion of there the context. In expression, the properties of the root object can be referenced without any special “marker” notion. References to other objects are marked with a pound sign (<code class="language-plaintext highlighter-rouge">#</code>).</p> -<p>The framework sets the OGNL context to be our ActionContext, and the value stack to be the OGNL root object. -(The value stack is a set of several objects, but to OGNL it appears to be a single object.) Along with the value stack, -the framework places other objects in the ActionContext, including Maps representing the application, session, -and request contexts. These objects coexist in the ActionContext, alongside the value stack (our OGNL root).</p> +<h2 id="context">Context</h2> + +<p>The framework sets the OGNL context to be our <code class="language-plaintext highlighter-rouge">ActionContext</code>, and the <code class="language-plaintext highlighter-rouge">ValueStack</code> to be the OGNL root object. +(The <code class="language-plaintext highlighter-rouge">ValueStack</code> is a set of several objects, but to OGNL it appears to be a single object). Along with the value stack, +the framework places other objects in the <code class="language-plaintext highlighter-rouge">ActionContext</code>, including maps representing the application, session, +and request contexts. These objects coexist in the <code class="language-plaintext highlighter-rouge">ActionContext</code>, alongside the value stack (our OGNL root).</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>context map---| |--application @@ -169,11 +172,11 @@ and request contexts. These objects coexist in the ActionContext, alongside the | </code></pre></div></div> -<p>The Action instance is always pushed onto the value stack. Because the Action is on the stack, and the stack is -the OGNL root, references to Action properties can omit the <code class="language-plaintext highlighter-rouge">#</code> marker. But, to access other objects in the ActionContext, -we must use the <code class="language-plaintext highlighter-rouge">#</code> notation so OGNL knows not to look in the root object, but for some other object in the ActionContext.</p> +<h2 id="referencing-an-action-property">Referencing an Action property</h2> -<p><strong>Referencing an Action property</strong></p> +<p>The Action instance is always pushed onto the value stack. Because the Action is on the stack, and the stack is +the OGNL root, references to Action properties can omit the <code class="language-plaintext highlighter-rouge">#</code> marker. But, to access other objects in the ActionContext, +we must use the <code class="language-plaintext highlighter-rouge">#</code> notation so OGNL knows not to look in the root object, but for some other object in the ActionContext.</p> <div class="language-jsp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><s:property </span><span class="na">value=</span><span class="s">"postalCode"</span><span class="nt">/></span> </code></pre></div></div> @@ -185,12 +188,6 @@ we must use the <code class="language-plaintext highlighter-rouge">#</code> nota <span class="nt"><s:property </span><span class="na">value=</span><span class="s">"#request['myRequestPropKey']"</span><span class="nt">/></span> </code></pre></div></div> -<p>The ActionContext is also exposed to Action classes via a static method but you <strong>should not</strong> use this approach. -Safer is to use one of the <code class="language-plaintext highlighter-rouge">*Aware</code> interfaces.</p> - -<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">ActionContext</span><span class="o">.</span><span class="na">getContext</span><span class="o">().</span><span class="na">getSession</span><span class="o">().</span><span class="na">put</span><span class="o">(</span><span class="s">"mySessionPropKey"</span><span class="o">,</span> <span class="n">mySessionObject</span><span class="o">);</span> -</code></pre></div></div> - <p>You can also put expression for attributes that don’t support dynamic content, like below:</p> <div class="language-jsp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><c:set </span><span class="na">var=</span><span class="s">"foo"</span><span class="na"> value=</span><span class="s">"bar"</span><span class="na"> scope=</span><span class="s">"request"</span><span class="nt">/></span> @@ -200,16 +197,16 @@ Safer is to use one of the <code class="language-plaintext highlighter-rouge">*A <h2 id="collections-maps-lists-sets">Collections (Maps, Lists, Sets)</h2> <p>Dealing with Collections (Maps, Lists, and Sets) in the framework comes often, so below please there are a few examples -using the select tag. The <a href="http://commons.apache.org/proper/commons-ognl/language-guide.html#Collection_Construction">OGNL documentation</a> +using tags. The <a href="https://github.com/orphan-oss/ognl/blob/master/docs/LanguageGuide.md#collection-construction">OGNL documentation</a> also includes some examples.</p> -<p>Syntax for list: <code class="language-plaintext highlighter-rouge">{e1,e2,e3}</code>. This idiom creates a List containing the String “name1”, “name2” and “name3”. It also -selects “name2” as the default value.</p> +<p>Syntax for a list: <code class="language-plaintext highlighter-rouge">{e1, e2, e3}</code>. This idiom creates a List containing the String “name1”, “name2” and “name3”. It also +selects “name2” as the default value:</p> <div class="language-jsp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><s:select </span><span class="na">label=</span><span class="s">"label"</span><span class="na"> name=</span><span class="s">"name"</span><span class="na"> list=</span><span class="s">"{'name1','name2','name3'}"</span><span class="na"> value=</span><span class="s">"%{'name2'}"</span> <span class="nt">/></span> </code></pre></div></div> -<p>Syntax for map: <code class="language-plaintext highlighter-rouge">#{key1:value1,key2:value2}</code>. This idiom creates a map that maps the string “foo” to the string +<p>Syntax for a map: <code class="language-plaintext highlighter-rouge">#{key1:value1, key2:value2}</code>. This idiom creates a map that maps the string “foo” to the string “foovalue” and “bar” to the string “barvalue”:</p> <div class="language-jsp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><s:select </span><span class="na">label=</span><span class="s">"label"</span><span class="na"> name=</span><span class="s">"name"</span><span class="na"> list=</span><span class="s">"#{'foo':'foovalue', 'bar':'barvalue'}"</span> <span class="nt">/></span> @@ -232,7 +229,7 @@ selects “name2” as the default value.</p> <span class="nt"></s:else></span> </code></pre></div></div> -<p>To select a subset of a collection (called projection), use a wildcard within the collection.</p> +<p>To select a subset of a collection, use a wildcard within the collection.</p> <ul> <li><code class="language-plaintext highlighter-rouge">?</code> - All elements matching the selection logic</li> @@ -242,38 +239,27 @@ selects “name2” as the default value.</p> <p>To obtain a subset of just male relatives from the object person:</p> -<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>person.relatives.{? #this.gender == 'male'} +<div class="language-jsp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><s:iterator </span><span class="na">value=</span><span class="s">"person.relatives.{? #this.gender == 'male'}"</span><span class="nt">></span> + ... +<span class="nt"></s:iterator></span> </code></pre></div></div> -<h2 id="lambda-expressions">Lambda Expressions</h2> +<p>You can also use projection to extract just a given property out of a bean:</p> -<p>OGNL supports basic lamba expression syntax enabling you to write simple functions. -(Dedicated to all you math majors who didn’t think you would ever see this one again.)</p> - -<p>Fibonacci:</p> -<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>if n == 0 - return 0; - elseif n == 1 - return 1; - else - return fib(n-2) + fib(n-1); - - - fib(0) = 0 - fib(1) = 1 - fib(11) = 89 +<div class="language-jsp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><s:iterator </span><span class="na">value=</span><span class="s">"persons.{firstName}"</span><span class="nt">></span> + <span class="nt"><s:property/></span> +<span class="nt"></s:iterator></span> </code></pre></div></div> -<p><strong>How the expression works</strong></p> +<p>it’s the same as using more expressive version:</p> -<blockquote> - <p>The lambda expression is everything inside the square brackets. The <code class="language-plaintext highlighter-rouge">#this</code> variable holds the argument to the expression, -which in the following example is the number 11 (the code after the square-bracketed lamba expression, <code class="language-plaintext highlighter-rouge">#fib(11)</code>).</p> -</blockquote> - -<div class="language-jsp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><s:property </span><span class="na">value=</span><span class="s">"#fib =:[#this==0 ? 0 : #this==1 ? 1 : #fib(#this-2)+#fib(#this-1)], #fib(11)"</span> <span class="nt">/></span> +<div class="language-jsp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><s:iterator </span><span class="na">value=</span><span class="s">"persons"</span><span class="na"> var=</span><span class="s">"person"</span><span class="nt">></span> + <span class="nt"><s:property </span><span class="na">value=</span><span class="s">"person.firstName"</span><span class="nt">/></span> +<span class="nt"></s:iterator></span> </code></pre></div></div> +<p>More details can can be found in OGNL documentation about <a href="https://ognl.orphan.software/language-guide#projecting-across-collections">projection</a>.</p> + </section> </article>