【问题标题】: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】:

您需要设置选中的属性。我可能会使用&lt;t:any&gt; 组件。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-28
    • 2022-01-15
    • 2019-07-08
    • 2013-10-12
    • 2016-02-14
    相关资源
    最近更新 更多