我在JSF中使用此代码:
<c:if test="#{sV.done.booleanValue()}">
<option value="#{sV.id}" selected="selected">#{sV.text}</option>
</c:if>
<c:if test="#{not sV.done.booleanValue()}">
<option value="#{sV.id}">#{sV.text}</option>
</c:if>
Run Code Online (Sandbox Code Playgroud)
sv
是我的包含数据(POJO)类,做的是一个Boolean
变量,我要显示option
与标签selected
,如果属性sV.done
是true
.但我做不到.不知道我哪里错了.
否则可能会出现问题c
,因为c:forEach
在我的案例中,在同一页面中有一段时间没有工作?这可能是原因吗?哪里错了?
每次显示没有选中的选项标签attribute
.
试试这个: -
<c:if test="${sV.done == true}">...</c:if> // or
<c:if test="${sV.done eq true}">...</c:if> // or
<c:if test="${sV.done}">...</c:if> // or
Run Code Online (Sandbox Code Playgroud)
而对于否定(如果sV.done为假): -
<c:if test="${! sV.done}">...</c:if> /// OR
<c:if test="${not sV.done}">...</c:if> /// OR
<c:if test = "${sV.done != true}">...</c:if> // OR
<c:if test = "${sV.done ne true}">...</c:if> // OR
Run Code Online (Sandbox Code Playgroud)
有关运营商的更多信息,请查看此链接: - JSTL if
如果您使用的是EL 2.2,那么您的语法很好.那么,没有一个JSTL <c:xxx>
标签被解释?您需要导入JSTL核心taglib.目前还不清楚您正在使用哪种视图技术和JSTL版本,因此这里是JSP和Facelets的导入示例.
使用JSTL 1.0的JSP:
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
Run Code Online (Sandbox Code Playgroud)
使用JSTL 1.1/1.2的JSP:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
Run Code Online (Sandbox Code Playgroud)
Facelets 1.x与JSTL 1.1/1.2:
<html ... xmlns:c="http://java.sun.com/jstl/core">
Run Code Online (Sandbox Code Playgroud)
Facelets 2.x与JSTL 1.2:
<html ... xmlns:c="http://java.sun.com/jsp/jstl/core">
Run Code Online (Sandbox Code Playgroud)
与具体问题无关,您是否考虑过使用JSF UISelectOne
组件而不是<option>
自己摆弄元素?您可以在我们的h:selectOneMenu
维基页面中找到一些具体示例.