matrei commented on code in PR #15304:
URL: https://github.com/apache/grails-core/pull/15304#discussion_r2687893809
##########
grails-doc/src/en/ref/Tag Libraries/session.adoc:
##########
@@ -35,14 +35,23 @@ The link:{servletApiRefFromRef}session.html[session] object
is an instance of th
----
class ExampleTagLib {
- def logout = {
- log.info "User agent: " + request.getHeader("User-Agent")
- session.invalidate()
+ // List all attributes and their values for the current session
+ def listSessionAttributes = { Map params ->
+ out << params.get("name") << ' : ' <<
session.getAttribute(params.get("name"))
}
}
----
+[source,xml]
+----
+<ul>
+ <g:each var="elm" in="${session.getAttributeNames()}">
+ <li><g:listSessionAttributes name="${elm}" /></li>
+ </g:each>
+</ul>
+----
+
Review Comment:
Hmm, I struggle to see the logic in this example. Making easy/clear examples
is hard.
Suggestion:
```groovy
class ExampleTagLib {
def oncePerSession = { Map attrs, body ->
def key = (attrs.key ?: 'default').toString()
def sessionKey = "taglib.oncePerSession.${key}"
if (!session.getAttribute(sessionKey)) {
session.setAttribute(sessionKey, true)
out << body()
}
}
}
```
```xml
<g:oncePerSession key="promo">
<div class="promo">Free shipping this week!</div>
</g:oncePerSession>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]