You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2026/10/16 05:39:00 UTC

[jira] [Work logged] (WW-5781) checkboxlist and radio render class and style attributes twice, cssErrorClass/cssErrorStyle never apply

     [ https://issues.apache.org/jira/browse/WW-5781?focusedWorklogId=1047746&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1047746 ]

ASF GitHub Bot logged work on WW-5781:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 16/Oct/26 05:38
            Start Date: 16/Oct/26 05:38
    Worklog Time Spent: 10m 
      Work Description: lukaszlenart opened a new pull request, #2026:
URL: https://github.com/apache/struts/pull/2026

   Fixes [WW-5781](https://issues.apache.org/jira/browse/WW-5781)
   
   ## Problem
   
   Both tags wrote `class`/`style` on each input themselves and then included `css.ftl`, which wrote them a second time. `<s:checkboxlist>` did this whenever `cssClass` or `cssStyle` was set; `<s:radio>` did it whenever `listCssClass` or `listCssStyle` was set:
   
   ```html
   <input type="checkbox" ... class="myClass" style="mystyle" class="myClass errclass" style="errstyle"/>
   ```
   
   Browsers keep the first copy of a duplicate attribute. So the error class and style that `css.ftl` adds came second and were dropped, which meant `cssErrorClass` and `cssErrorStyle` never took effect on these inputs.
   
   ## Fix
   
   A new shared include, `template/simple/list-item-css.ftl`, writes exactly one `class` and one `style` per item. The html5 theme picks it up through its parent theme, `simple`.
   
   - **class:** `listCssClass` if it is non-empty, otherwise `cssClass`. When the field has errors, `cssErrorClass` is appended.
   - **style:** `cssErrorStyle` when the field has errors and it is set. Otherwise `listCssStyle` if non-empty, otherwise `cssStyle`, which is dropped when an error class applies (the existing `css.ftl` rule).
   
   The item value replacing the tag value is what browsers already render today, so ordinary pages look the same. `css.ftl` itself is unchanged, so the other tags and any custom themes that override it are unaffected. The radio `<label>` still uses `css.ftl`, as before.
   
   **What changes for users:**
   - `cssErrorClass` and `cssErrorStyle` now work on checkbox and radio items.
   - Checkboxlist with a `listCssClass` that evaluates to an empty string used to render `class=""` first, which hid `cssClass`. It now falls back to `cssClass`, as radio already did.
   - Checkboxlist with field errors, `cssErrorClass` and `cssStyle` (but no `cssErrorStyle`) no longer renders `cssStyle`. This matches `css.ftl` and every other tag.
   
   ## Tests
   
   - New expected-output fixtures for checkboxlist (`cssClass` only, item class replacing `cssClass`, field errors) and for radio (item class in simple and html5, field errors). An html5 checkboxlist test counts the `class`/`style` attributes rather than comparing a whole fixture, because the html5 checkboxlist markup is being fixed separately in #2025. All 7 new tests failed before the fix, on the duplicate attributes.
   - `FreemarkerResultMockedTest` loads templates only from a mocked servlet context and allows each template by name, so it needed the new include added to that list.
   - `mvn test -pl core`: 3479 tests, 0 failures.
   
   Merges with #2025 (WW-5780) without conflicts.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)




Issue Time Tracking
-------------------

            Worklog Id:     (was: 1047746)
    Remaining Estimate: 0h
            Time Spent: 10m

> checkboxlist and radio render class and style attributes twice, cssErrorClass/cssErrorStyle never apply
> -------------------------------------------------------------------------------------------------------
>
>                 Key: WW-5781
>                 URL: https://issues.apache.org/jira/browse/WW-5781
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - Tags
>            Reporter: Lukasz Lenart
>            Priority: Major
>             Fix For: 7.5.0
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> {{template/simple/checkboxlist.ftl}} (also used by {{xhtml}}) and {{template/html5/checkboxlist.ftl}} write {{class}} and {{style}} on each checkbox themselves (from {{listCssClass}}/{{listCssStyle}}, falling back to {{cssClass}}/{{cssStyle}}) and then include {{css.ftl}}, which writes {{class}} and {{style}} again.
> Rendering {{<s:checkboxlist name="collection" list="list" listKey="top[0]" listValue="top[1]" cssClass="myClass" cssStyle="width:150px"/>}} with the simple theme produces:
> {code:html}<input type="checkbox" name="collection" value="hello" id="collection-1" class="myClass" style="width:150px" class="myClass" style="width:150px" />
> {code}
> and with {{listCssClass="'itemClass'"}} added:
> {code:html}<input type="checkbox" ... class="itemClass" style="width:150px" class="myClass" style="width:150px" />
> {code}
> {{template/simple/radiomap.ftl}} and {{template/html5/radiomap.ftl}} (the {{s:radio}} tag) have the same defect whenever {{listCssClass}} or {{listCssStyle}} is set: the item {{class}}/{{style}} is written, then {{css.ftl}} writes the tag-level ones again.
> Duplicate attributes are invalid HTML and browsers keep only the first occurrence. With field errors present, the {{class="myClass errclass"}} / {{cssErrorStyle}} value written by {{css.ftl}} comes second and is dropped, so {{cssErrorClass}} and {{cssErrorStyle}} have no effect on these inputs.
> Expected: each checkbox/radio input carries a single {{class}} and a single {{style}} attribute. {{listCssClass}}/{{listCssStyle}} replace {{cssClass}}/{{cssStyle}} (what browsers render today), {{cssErrorClass}} is appended and {{cssErrorStyle}} applied when the field has errors, following the {{css.ftl}} rules. No existing test covers {{cssClass}} on these inputs.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)