2012-07-23 61 views
7

在我的jsp中,对于某些条件,我希望复选框存在,但不希望允许用户检查它或取消选中它。如何禁用弹簧窗体复选框?

我不知道我怎么能做到这一点。我试过以下

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

没有什么似乎工作。

有人可以对此有所了解吗?

谢谢..在<spring:checkbox>

回答

18

disabled属性应该是设置为truefalse和复选框没有readonly属性。所以

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

应该工作。

几个链接
Spring doc link.
Readonly and Disabled property in Spring form input

您可以使用JSTL它取决于一些条件

<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> 
+1

较短的方式做补充,这可能是** <形式:复选框路径=” desiredpath“disabled =”$ {requestScope.trueOrFalse}“/> ** – OJVM 2017-03-03 16:20:39

+0

@OJVM是更清洁。 – xyz 2017-07-26 13:12:19