provençal le breton
provençal le breton

Reputation: 1438

Get checkbox is check or not without js

I have a form with a checkbox input:

<form:input id="garder_${indice}" path="mesFormulaires[${indice}].garder"
    type="text" name="garder_${indice}" />

I want to get if the checkbox is checked or not in Java. How is it possible, using getter/setter with a boolean named "garder". I hope it's possible with Java methods, but I don't know them.

Upvotes: 0

Views: 490

Answers (1)

davioooh
davioooh

Reputation: 24676

If you are using Spring MVC I suggest you to use the form:checkbox tag and bind it to a property of the modelAttribute object of your form.

public class YourModelAttribute{
    private boolan checkBoxProp;
    // other props

    // getter and setter for your props
}

Then in your page:

<form:checkbox id="ckbId" path="checkBoxProp" />

Be sure to set as modelAttribute of your form an instance of YourModelAttribute.

Upvotes: 1

Related Questions