You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2023/05/19 11:13:28 UTC

[struts-site] branch WW-5307-ognl updated (b601bbd71 -> 68f40773e)

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch WW-5307-ognl
in repository https://gitbox.apache.org/repos/asf/struts-site.git


 discard b601bbd71 WW-5307 Cleans up OGNL related pages
     new 68f40773e WW-5307 Cleans up OGNL related pages

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (b601bbd71)
            \
             N -- N -- N   refs/heads/WW-5307-ognl (68f40773e)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 source/tag-developers/ognl.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[struts-site] 01/01: WW-5307 Cleans up OGNL related pages

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5307-ognl
in repository https://gitbox.apache.org/repos/asf/struts-site.git

commit 68f40773e63a8e749c7af00bdc9b9fe2e157df24
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Fri May 19 12:49:23 2023 +0200

    WW-5307 Cleans up OGNL related pages
---
 source/tag-developers/ognl-basics.md | 101 ++++++++++++-----------------------
 source/tag-developers/ognl.md        |  23 ++++----
 2 files changed, 42 insertions(+), 82 deletions(-)

diff --git a/source/tag-developers/ognl-basics.md b/source/tag-developers/ognl-basics.md
index 688ab54ab..400087c4a 100644
--- a/source/tag-developers/ognl-basics.md
+++ b/source/tag-developers/ognl-basics.md
@@ -14,11 +14,11 @@ parent:
 
 ## Struts-specific language features
 
-The biggest addition that Struts provides on top of OGNL is the support for the ValueStack. While OGNL operates under 
+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".
 
-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 **root** object. 
+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 **root** object.
 The following code illustrates how OGNL deals with these three situations:
 
 ```
@@ -27,17 +27,17 @@ The following code illustrates how OGNL deals with these three situations:
 blah      // returns foo.getBlah() because foo is the root
 ```
 
-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...
+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...
 
-> 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.
+> 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.
 
-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:
+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:
 
 ```
 species    // call to animal.getSpecies()
@@ -45,29 +45,30 @@ salary     // call to person.getSalary()
 name       // call to animal.getName() because animal is on the top
 ```
 
-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:
+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:
 
 ```
 [0].name   // call to animal.getName()
 [1].name   // call to person.getName()
 ```
 
-With expression like `[0] ... [3]` etc. Struts will cut the stack and still return back a CompoundRoot object. To get 
+With expression like `[0] ... [3]` etc. Struts will cut the stack and still return back a CompoundRoot object. To get
 the top of that particular stack cut, use `[0].top`
 
-|ognl expression|description|
-|---------------|-----------|
-|`[0].top`|would get the top of the stack cut starting from element 0 in the stack (similar to top in this case)|
-|`[1].top`|would get the top of the stack cut starting from element 1 in the stack|
+| ognl expression | description                                                                                           |
+|-----------------|-------------------------------------------------------------------------------------------------------|
+| `[0].top`       | would get the top of the stack cut starting from element 0 in the stack (similar to top in this case) |
+| `[1].top`       | would get the top of the stack cut starting from element 1 in the stack                               |
 
 ### Accessing static properties
 
 OGNL supports accessing static properties as well as static methods.
 
 By default, Struts 2 is configured to disallow this - to enable OGNL's static member support you must set the
-`struts.ognl.allowStaticMethodAccess` constant to `true` via any of the [Constant Configuration](../core-developers/constant-configuration) methods.
+`struts.ognl.allowStaticMethodAccess` constant to `true` via any 
+of the [Constant Configuration](../core-developers/constant-configuration) methods.
 
 OGNL's static access looks like this:
 
@@ -76,52 +77,16 @@ OGNL's static access looks like this:
 @some.package.ClassName@someMethod()
 ```
 
-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:
-
-```
-<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()
-```
-
-"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.
-
-### Differences from the WebWork 1.x EL
-
-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.
-
-|Old Expression|New Expression|
-|--------------|--------------|
-|foo/blah|foo.blah|
-|foo/someMethod()|foo.someMethod()|
-|../bar/blah|[1].bar.blah|
-|@baz|not directly supported, but #baz is similar|
-|.|'top' or [0]|
-
 ### Struts 2 Named Objects
 
-Struts 2 places request parameters and request, session, and application attributes on the OGNL stack. They may be accessed 
-as shown below.
-
-|name|value|
-|----|-----|
-|#action['foo'] or #action.foo|current action getter (getFoo())|
-|#parameters['foo'] or #parameters.foo|request parameter ['foo'] (request.getParameter())|
-|#request['foo'] or #request.foo|request attribute ['foo'] (request.getAttribute())|
-|#session['foo'] or #session.foo|session attribute 'foo'|
-|#application['foo'] or #application.foo|ServletContext attributes 'foo'|
-|#attr['foo'] or #attr.foo|Access to PageContext if available, otherwise searches request/session/application respectively|
+Struts 2 places request parameters and request, session, and application attributes on the OGNL stack. They may be
+accessed as shown below.
+
+| name                                    | value                                                                                           |
+|-----------------------------------------|-------------------------------------------------------------------------------------------------|
+| #action['foo'] or #action.foo           | current action getter (getFoo())                                                                |
+| #parameters['foo'] or #parameters.foo   | request parameter ['foo'] (request.getParameter())                                              |
+| #request['foo'] or #request.foo         | request attribute ['foo'] (request.getAttribute())                                              |
+| #session['foo'] or #session.foo         | session attribute 'foo'                                                                         |
+| #application['foo'] or #application.foo | ServletContext attributes 'foo'                                                                 |
+| #attr['foo'] or #attr.foo               | Access to PageContext if available, otherwise searches request/session/application respectively |
diff --git a/source/tag-developers/ognl.md b/source/tag-developers/ognl.md
index 9fd1fbc36..2d2d5353c 100644
--- a/source/tag-developers/ognl.md
+++ b/source/tag-developers/ognl.md
@@ -12,7 +12,7 @@ parent:
 * Will be replaced with the ToC, excluding a header
 {:toc}
 
-OGNL is the Object Graph Navigation Language (see [http://commons.apache.org/proper/commons-ognl/] for the full 
+OGNL is the Object Graph Navigation Language (see [OGNL page](https://ognl.orphan.software/) 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 [OGNL Basics](ognl-basics).
 
@@ -62,13 +62,6 @@ Other (non-root) objects in the ActionContext can be rendered use the `#` notati
 <s:property value="#request['myRequestPropKey']"/>
 ```
 
-The ActionContext is also exposed to Action classes via a static method but you **should not** use this approach. 
-Safer is to use one of the `*Aware` interfaces. 
-
-```java
-ActionContext.getContext().getSession().put("mySessionPropKey", mySessionObject);
-```
-
 You can also put expression for attributes that don't support dynamic content, like below:
 
 ```jsp
@@ -79,7 +72,7 @@ You can also put expression for attributes that don't support dynamic content, l
 ## Collections (Maps, Lists, Sets)
 
 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 [OGNL documentation](http://commons.apache.org/proper/commons-ognl/language-guide.html#Collection_Construction)
+using the select tag. The [OGNL documentation](https://github.com/orphan-oss/ognl/blob/master/docs/LanguageGuide.md#collection-construction)
 also includes some examples.
 
 Syntax for list: `{e1,e2,e3}`. This idiom creates a List containing the String "name1", "name2" and "name3". It also 
@@ -114,7 +107,7 @@ To determine if an element exists in a Collection, use the operations `in` and `
 </s:else>
 ```
 
-To select a subset of a collection (called projection), use a wildcard within the collection.
+To select a subset of a collection, use a wildcard within the collection.
 
 - `?` - All elements matching the selection logic
 - `^` - Only the first element matching the selection logic
@@ -123,12 +116,14 @@ To select a subset of a collection (called projection), use a wildcard within th
 To obtain a subset of just male relatives from the object person:
 
 ```
-person.relatives.{? #this.gender == 'male'}
+<s:iterator value="person.relatives.{? #this.gender == 'male'}">
+  ...
+</s:iterator>
 ```
 
 ## Lambda Expressions
 
-OGNL supports basic lamba expression syntax enabling you to write simple functions.
+OGNL supports basic lambda 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.)
 
 Fibonacci: 
@@ -148,8 +143,8 @@ if n == 0
 
 **How the expression works**
 
-> The lambda expression is everything inside the square brackets. The `#this` variable holds the argument to the expression, 
-> which in the following example is the number 11 (the code after the square-bracketed lamba expression, `#fib(11)`).
+The lambda expression is everything inside the square brackets. The `#this` variable holds the argument to the expression, 
+which in the following example is the number 11 (the code after the square-bracketed lambda expression, `#fib(11)`).
 
 ```jsp
 <s:property value="#fib =:[#this==0 ? 0 : #this==1 ? 1 : #fib(#this-2)+#fib(#this-1)], #fib(11)" />