Lukasz Lenart created WW-5781:
---------------------------------

             Summary: checkboxlist renders 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
             Fix For: 7.5.0


{{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}

Duplicate attributes are invalid HTML and browsers keep only the first 
occurrence. As a consequence, when the field has errors the {{class="myClass 
error"}} / {{cssErrorStyle}} value written by {{css.ftl}} comes second and is 
dropped, so {{cssErrorClass}} and {{cssErrorStyle}} have no effect on 
checkboxlist (follows from the HTML parsing rule; the field-error case was not 
rendered).

{{radiomap.ftl}} does not have this problem — it relies on {{css.ftl}} alone 
for the input.

Expected: each checkbox carries a single {{class}} and a single {{style}} 
attribute; per-item {{listCssClass}}/{{listCssStyle}} take precedence over 
{{cssClass}}/{{cssStyle}}, and the error class/style is applied when the field 
has errors. No existing test covers {{cssClass}} on the simple-theme 
checkboxlist.



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

Reply via email to