質問

I am using plain HTML checkbox(not Tapestry type). I need to set the checkbox to checked in my java page. How do I do that?

Here is my tml code fragment

<input type="checkbox" name="leaf" id="leaf" value="leaf"/>

Any help would be appreciated. Thanks.

役に立ちましたか?

解決

You need to set the checked property. I'd probably use the <t:any> component.

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;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top