如何禁用Spring表单复选框?

10

在我的JSP中,对于某些条件,我希望复选框存在,但不希望用户能够选择或取消选中。

我不确定如何实现这一点。我尝试了以下方法:

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

似乎什么都不起作用。

有人能为此提供一些启示吗?

谢谢..

1个回答

21

<spring:checkbox> 中的 disabled 属性应该设置为 truefalse,复选框没有 readonly 属性。因此,

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

应该可以工作。

一些链接
Spring文档链接。
在Spring表单输入中使用只读和禁用属性

您可以使用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>   

2
一个更简短的方法是 **<form:checkbox path="desiredPAth" disabled="${requestScope.trueOrFalse}" />**。 - OJVM
1
@OJVM 是的,干净多了。 - Ajinkya

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接