Repository navigation
WW-3476 docs: document package-scoped constants - #351
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lukaszlenart
left a comment
There was a problem hiding this comment.
Checked against apache/struts main (WW-3476, merged as fd60b2073):
dtds/struts-7.5.dtdanddtds/struts-6.5.dtdare byte-identical tocore/src/main/resources/onmain; 6.5 also matches theSTRUTS_6_12_0tag. https://struts.apache.org/dtds/struts-6.5.dtd currently returns 404, so publishing it fixes a real gap.- These behaviour claims match the code:
- the child package's override wins;
<scoped-constant>must come first in<package>;- abstract packages are validated, and the error lists the scopable names;
- a duplicate name fails;
getValuefalls back to the global value, returnsnullwhen that is unset, and throwsIllegalArgumentExceptionfor a name that is not scopable;- the injected global value is never changed.
- The note that
${...}is not substituted is accurate for the current code (XmlDocConfigurationProvider.loadScopedConstantsstores the raw attribute). - The anchors
action-mapper#prefixbasedactionmapper,constant-configuration#value-substitutionandplugins-architecture#extension-pointsall resolve. - The extension-point row has the right property, scope and interface.
A few suggestions are inline. Nothing blocks the PR.
| ```java | ||
| private ScopedConstantProvider scopedConstantProvider; | ||
|
|
||
| @Inject |
There was a problem hiding this comment.
Suggest showing the imports here, at least import org.apache.struts2.inject.Inject;. Readers tend to reach for jakarta.inject.Inject / javax.inject.Inject, which the Struts container ignores, so the setter would silently never be called. Adding the ScopableConstants / ScopedConstantProvider imports to the two snippets would help too.
There was a problem hiding this comment.
Done in 1d215b5. Both snippets now show their imports, including org.apache.struts2.inject.Inject. An info note under the snippets explains that the container ignores jakarta.inject.Inject / javax.inject.Inject.
| ## Scoped constants | ||
|
|
||
| Since Struts 7.5.0 a package can override selected [constants](constant-configuration) for its own actions with | ||
| the `<scoped-constant>` element. Packages that `extends` it inherit the override, and an override declared in |
There was a problem hiding this comment.
Two small additions could go here:
- With several parents (
extends="a,b"), the first listed parent wins on a conflict, the same rule as result types. - Packages built by the Convention plugin get overrides only by inheriting them from their XML parent package (
@ParentPackage).
There was a problem hiding this comment.
Done in 1d215b5. Both points are added. I checked the first-parent rule against the code: PackageConfig.Builder.addParent inserts at index 0, so the first package in extends is merged last and wins. For Convention I also mentioned struts.convention.default.parent.package, since it is the fallback when @ParentPackage is missing.
| The error message lists the scopable constants that are available. | ||
| - a package declares the same constant more than once. | ||
|
|
||
| Values are used as they are. Unlike in `<constant>`, `${...}` [value substitution](constant-configuration#value-substitution) |
There was a problem hiding this comment.
There was a problem hiding this comment.
Leaving this as is for now. If WW-5767 lands before 7.5.0, the sentence will be replaced with a link to value substitution.
| `struts.enable.DynamicMethodInvocation` or `struts.devMode`. Otherwise a single package can relax a setting | ||
| meant to protect the whole application. | ||
|
|
||
| The default `ScopedConstantProvider` implementation can be replaced with the `struts.scopedConstantProvider` |
|
Staged site is ready at https://struts.staged.apache.org/ |
1 similar comment
|
Staged site is ready at https://struts.staged.apache.org/ |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Staged site is ready at https://struts.staged.apache.org/ |
Refers to WW-3476 and apache/struts#2005 (merged, fix version 7.5.0)
Documents the
<scoped-constant>element added in 7.5.0, which lets a package override selected constants for its own actions. Packages thatextendsit inherit the override.core-developers/package-configuration.md: a new "Scoped constants" section. It covers the element and its DTD, inheritance, the startup errors (a name nothing has declared scopable, or a duplicate name), and the lack of${...}substitution. A "Making a constant scopable" part is for component authors: register aScopableConstantsbean and read values throughScopedConstantProvider. It also covers which constants can never be scoped (PrefixBasedActionMapperhandles per-URL mappers) and warns against making security switches scopable.core-developers/constant-configuration.md: a link to the new section.plugins/plugins-architecture.md: astruts.scopedConstantProviderrow in the Extension Points table.dtds/struts-7.5.dtd: copied from apache/strutsmain. Publishing it is the follow-up listed in WW-3476 Add package-scoped constants struts#2005.dtds/struts-6.5.dtd: this file was never published, sohttps://struts.apache.org/dtds/struts-6.5.dtd, the system id in the 6.5 DOCTYPE, returns 404. The copy is from apache/strutsmainand is identical to theSTRUTS_6_12_0tag.The section states that Struts core does not declare any constant as scopable yet, as of apache/struts#2005. If a scopable constant (UI theme, i18n, Convention result path) lands before 7.5.0, that warning needs updating.
Verified with a local
jekyll build: the new anchors resolve, both alerts render, and both DTDs are published under_site/dtds/.🤖 Generated with Claude Code