我在Spring MVC的JAVA项目中工作。
我想制作带复选框的表单,但是, 我有自定义复选框,所以我不能使用spring的形式:复选框。
所以我尝试制作一个c:foreach循环来显示我的复选框:
<c:forEach var="element" items="${targetableBars}" varStatus="status">
<div class="checkboxElement">
<div class="squaredOne">
<input id="targetedBarIds<c:out value="$(status.index)"/>" name="targetedBarIds" type="checkbox" class="squaredInput" value="<c:out value="$(status.index)"/>" checked="checked">
<label for="targetedBarIds$(status.index)"></label>
</div>
<span>$(element.name)</span>
</div>
</c:forEach>
并显示:
<div class="checkboxElement">
<div class="squaredOne">
<input id="targetedBarIds$(status.index)" name="targetedBarIds" type="checkbox" class="squaredInput" value="$(status.index)" checked="checked">
<label for="targetedBarIds$(status.index)"></label>
</div>
<span>$(element.name)</span>
</div>
<div class="checkboxElement">
<div class="squaredOne">
<input id="targetedBarIds$(status.index)" name="targetedBarIds" type="checkbox" class="squaredInput" value="$(status.index)" checked="checked">
<label for="targetedBarIds$(status.index)"></label>
</div>
<span>$(element.name)</span>
</div>
<div class="checkboxElement">
<div class="squaredOne">
<input id="targetedBarIds$(status.index)" name="targetedBarIds" type="checkbox" class="squaredInput" value="$(status.index)" checked="checked">
<label for="targetedBarIds$(status.index)"></label>
</div>
<span>$(element.name)</span>
</div>
不评估循环中的EL而不是forEach上的EL!
我在web.xml上读到了一些内容:我改变了它但没有更好的东西:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
</web-app>
这是完整的JSP:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@page session="true"%>
<%@page isELIgnored="false" %>
<div class="form-header">
<h1 class="title">${title}</h1>
<h2 class="subtitle"><span><img class="subtitleImg" src="images/edit_L.png" /> Create a news</span></h2>
</div>
<div class="form-body">
<form id="createNews" class="form form-vertical" action="/meltdown/bo/createnews" method="POST" enctype="multipart/form-data">
<div class="control-group">
<label>Title</label>
<div class="controls">
<input id="newsDisplayer.title" name="newsDisplayer.title" type="text" placeholder="Title">
</div>
</div>
<div class="control-group textarea">
<label>Content</label>
<div class="controls">
<textarea id="newsDisplayer.text" name="newsDisplayer.text" placeholder="Content..."></textarea>
</div>
</div>
<div class="control-group">
<label>Image</label>
<div class="controls fileUpload">
<input type="file" name="imageUpload" accept="image/*" value="" placeholder="Choose File">
</div>
</div>
<div class="control-group">
<label>Date</label>
<div class="controls">
<input id="date" name="newsDisplayer.date" type="text" value="">
</div>
</div>
<div class="control-group">
<label>Targeted Bars</label>
<div class="controls">
<c:forEach var="element" items="${targetableBars}" varStatus="status">
<div class="checkboxElement">
<div class="squaredOne">
<input id="targetedBarIds<c:out value="$(status)"/>" name="targetedBarIds" type="checkbox" class="squaredInput" value="<c:out value="$(status.index)"/>" checked="checked">
<label for="targetedBarIds$(status)"></label>
</div>
<span>$(element.name)</span>
</div>
</c:forEach>
<input type="hidden" name="_targetedBarIds" value="on">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">
Publish
</button>
</div>
</div>
</form>
</div>
<span class="btn btn-success fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<span>Select files...</span>
<!-- The file input field used as target for the file upload widget -->
<input id="fileupload" type="file" name="files[]">
</span>
<br>
<br>
<!-- The global progress bar -->
<div id="progress" class="progress">
<div class="progress-bar progress-bar-success"></div>
</div>
<script type="text/javascript" >
$('#date').datetimepicker({
timepicker:false,
format:'d.m.Y'
});
</script>
<script src="<c:url value='/resources/js/singlefileupload.js' />"></script>
谢谢!
答案 0 :(得分:2)
<label for="targetedBarIds$(status.index)"></label>
你不想要花括号吗?更像是${status.index}
?