lakshmi
lakshmi

Reputation: 385

how to disable spring form checkbox?

In my jsp, for certain conditions I want the checkbox to be present but do not want to allow the user to check it or uncheck it.

I am not sure how I can achieve this. I tried the following

<form:checkbox path="..." disabled = "disabled"> 
<form:checkbox path="..." disabled = "true"> 
<form:checkbox path="..." readonly = "readonly"> 

Nothing seem to work.

Can someone throw some light on this?

Thanks..

Upvotes: 10

Views: 21662

Answers (1)

Ajinkya
Ajinkya

Reputation: 22710

disabled attribute in <spring:checkbox> should be either set to true or false and checkbox don't have readonly attribute. So

<form:checkbox path="corespondingPath" disabled = "true">   

should work.

Few link
Spring doc link.
Readonly and Disabled property in Spring form input

You can use JSTL to add it depending on some condition

<c:choose>
    <c:when test="${condition}">
          // Add checkbox with disabled="true"
          <form:checkbox path="desiredPAth" disabled="true" />
    </c:when>
    <c:otherwise>
          // Do something else
    </c:otherwise>
</c:choose>   

Upvotes: 21

Related Questions