Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable spring form checkbox?

Tags:

spring

jsp

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..

like image 527
lakshmi Avatar asked Jul 23 '12 21:07

lakshmi


1 Answers

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>   
like image 52
Ajinkya Avatar answered Oct 16 '22 10:10

Ajinkya