[
https://issues.apache.org/jira/browse/WW-5774?focusedWorklogId=1051553&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1051553
]
ASF GitHub Bot logged work on WW-5774:
--------------------------------------
Author: ASF GitHub Bot
Created on: 31/Oct/26 05:33
Start Date: 31/Oct/26 05:33
Worklog Time Spent: 10m
Work Description: Copilot commented on code in PR #2074:
URL: https://github.com/apache/struts/pull/2074#discussion_r4430688101
##########
core/src/main/resources/template/simple/combobox.ftl:
##########
@@ -18,25 +18,13 @@
* under the License.
*/
-->
-<@s.script>
- function autoPopulate_${attributes.escapedId}(targetElement) {
- <#if attributes.headerKey?? && attributes.headerValue??>
- if (targetElement.options[targetElement.selectedIndex].value ==
'${attributes.headerKey?js_string}') {
- return;
- }
- </#if>
- <#if attributes.emptyOption!false>
- if (targetElement.options[targetElement.selectedIndex].value ==
'') {
- return;
- }
- </#if>
-
targetElement.form.elements['${attributes.name?js_string}'].value=targetElement.options[targetElement.selectedIndex].value;
- }
-</@s.script>
+<@s.script src="${base}${attributes.staticContentPath}/combobox.js" />
Review Comment:
Non-blocking: each combobox emits a synchronous external script tag, so
rendering N comboboxes executes the script N times despite the listener guard.
Guard the include with a shared value-stack flag, following
`template/simple/inputtransferselect.ftl:21–24`, to avoid repeated execution
and parser blocking. Apply the same guard in
`core/src/main/resources/template/html5/combobox.ftl:21` so mixed-theme pages
also include the script only once.
Issue Time Tracking
-------------------
Worklog Id: (was: 1051553)
Time Spent: 20m (was: 10m)
> Move combobox change handling into a static script with a delegated listener
> ----------------------------------------------------------------------------
>
> Key: WW-5774
> URL: https://issues.apache.org/jira/browse/WW-5774
> Project: Struts 2
> Issue Type: Improvement
> Components: Core Tags
> Reporter: Lukasz Lenart
> Priority: Major
> Fix For: 7.5.0
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> h2. Problem
> After WW-5772 the transfer-select and updownselect tags bind their buttons
> from a static script through one delegated listener. The combobox tag removes
> its inline {{onChange}} too, but it does so by emitting a per-instance inline
> script block (through the {{s.script}} directive, so it carries the nonce)
> that binds every select marked with {{data-struts-combobox}}.
> That leaves three issues:
> * A Content-Security-Policy based on script hashes or on static scripts only
> still blocks the combobox, while the transfer selects work under it.
> * The binding block is duplicated verbatim in
> {{template/simple/combobox.ftl}} and {{template/html5/combobox.ftl}}, so any
> change has to be made twice.
> * N comboboxes rendered in an iterator emit N script blocks, each scanning
> the page with {{querySelectorAll}}, plus N redefinitions of the
> {{autoPopulate_}} function.
> h2. Proposal
> Add a static {{combobox.js}} with a single delegated {{change}} listener that
> reads the target field from data attributes on the select, matching the
> approach WW-5772 uses for the transfer selects. The templates then emit no
> per-instance inline script.
> Related: WW-5772
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)