【问题标题】:Tapestry: How to set HTML checkbox from java pageTapestry:如何从 Java 页面设置 HTML 复选框
【发布时间】:2013-07-09 10:59:28
【问题描述】:
我使用的是纯 HTML 复选框(不是 Tapestry 类型)。我需要将复选框设置为在我的 java 页面中选中。我该怎么做?
这是我的 tml 代码片段
<input type="checkbox" name="leaf" id="leaf" value="leaf"/>
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签:
java
html
checkbox
tapestry
checked
【解决方案1】:
您需要设置选中的属性。我可能会使用<t:any> 组件。
TML
<t:any element="input" type="literal:checkbox" name="literal:leaf" id="prop:clientId" value="prop:currentObject.value" checked="prop:checked" />
JAVA
@Property
private SomeType currentObject;
public String getClientId() {
return "mycheckbox_" + currentObject.getId();
}
// if this returns null, tapestry won't render the attribute
public String getChecked() {
return currentObject.isSelected() ? "checked" : null;
}