gpt4 book ai didi

java - EL 内部 c :foreach are not evaluated

转载 作者:行者123 更新时间:2023-12-02 05:38:01 25 4
gpt4 key购买 nike

我使用 Spring MVC 从事 JAVA 项目。

我想制作一个带有复选框的表单,但是,我自定义了checkbox,所以无法使用spring的form:checkboxes。

所以我尝试创建一个 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 conf 上读到了一些内容:我更改了它,但没有更好的了:

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

谢谢!!

最佳答案

<label for="targetedBarIds$(status.index)"></label>

你不需要花括号吗?更像${status.index}

关于java - EL 内部 c :foreach are not evaluated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24785321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com