简体   繁体   English

Struts2:复选框 - 隐藏不需要的输入类型

[英]Struts2 s:checkbox - unwanted input type hidden

My code: 我的代码:

<label class="btn btn-default">
    <s:checkbox name="viewTypeDescr" />&#32;
    <s:text name="name.contentType" />
</label>

The docs: http://struts.apache.org/release/2.3.x/docs/checkbox.html say that it will render a input[type=checkbox] 文档: http//struts.apache.org/release/2.3.x/docs/checkbox.html说它将呈现input[type=checkbox]

Instead here's what I get: 相反,这是我得到的:

<label class="btn btn-default">
    <input type="checkbox" name="viewTypeDescr" value="true" id="search_viewTypeDescr">
    <input type="hidden" id="__checkbox_search_viewTypeDescr" name="__checkbox_viewTypeDescr" value="true"> 
    Content Type
</label>

That added input[type="hidden"] is making the resulting page invalid because a label can have max 1 input inside. 添加input[type="hidden"]使得结果页面无效,因为标签内部可以有最多1个输入。

Definition of invalid: 无效的定义:

  1. Go to validator.w3.org 转到validator.w3.org
  2. Paste the provided HTML code in "Validate by direct input" 将提供的HTML代码粘贴到“通过直接输入验证”
  3. Decor it with missing <html><head><title>foo</title></head><body> and </body></html> to lessen the false errors 装饰它缺少<html><head><title>foo</title></head><body></body></html>以减少错误错误
  4. Select HTML5 ad doctype 选择HTML5广告文档类型
  5. Click "Validate" 点击“验证”
  6. Get this error: "Line xyz, Column abc: The label element may contain at most one input, button, select, textarea, or keygen descendant." 得到此错误:“行xyz,列abc:标签元素最多可包含一个输入,按钮,选择,textarea或keygen后代。”
  7. Go to spec just in case: "The caption can be associated with a specific form control, known as the label element's labeled control, either using the for attribute, or by putting the form control inside the label element itself." 转到spec以防万一:“标题可以与特定的表单控件相关联,称为标签元素的标记控件,使用for属性,或者将表单控件放在label元素本身中。”
  8. Discover that "If the for attribute is not specified, but the label element has a labelable element descendant, then the first such descendant in tree order is the label element's labeled control." 发现“如果未指定for属性,但label元素具有可变元素后代,则树序中的第一个这样的后代是标签元素的标记控件。”
  9. Add that hidden can't be there " http://www.w3.org/html/wg/drafts/html/master/forms.html#category-label " 添加隐藏的不能存在“ http://www.w3.org/html/wg/drafts/html/master/forms.html#category-label

Anyway, when you submit your document to QA for validation, they use validator.w3.org and that is all that matters. 无论如何,当您将文档提交给QA进行验证时,他们会使用validator.w3.org,这就是最重要的。

What's the reason of that hidden? 隐藏的原因是什么? How could I get rid of it or move it elsewhere? 我怎么能摆脱它或移动到其他地方?

I created a new theme, with parent=simple, and will use that. 我用parent = simple创建了一个新主题,并将使用它。

Still don't know what's the supposed purpose of that hidden... 仍然不知道隐藏的假设目的是什么......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM