将表单元素值获取到 jstl
我无法将表单元素值放入 jstl 标记中。我在 jsp 页面中做了一些奇特的东西,就像我有一个下拉菜单,一旦选择了某个值,我就加载表单的其余部分,一旦选择了它,我就加载其余部分,所以对于第一个下拉菜单我没有任何问题,因为它们是常量,我知道接下来要加载什么,但是我的第二个下拉菜单包含来自服务器的动态数据,所以我需要知道用户选择了什么,这样我就可以基于此加载表单的其余部分。
我无法在 jstl 中访问该表单元素值。我该怎么办?
我的jsp:
<head>
<script type="text/javascript">
$(document).ready(function(){
$("#implementation").change(function(){
if ($(this).val() == "aaa" ) {
$("#aaa").slideDown("fast");
} else {
$("#aaa").slideUp("fast");
}
});
$("#type").change(function(){
if ($(this).val() == "new" || $(this).val() == "old") {
$("#remote").slideDown("fast");
} else {
$("#remote").slideUp("fast");
}
});
});
</script>
</head>
<body>
<form:form id="form" name="form" method="post" modelAttribute="store" action="/shard">
<fieldset>
<div class="input select">
<label for="implementation">Implementation<span class="small">Choose implementation</span></label>
<form:select name="implementation" path="implementation">
<form:option value="">Choose Implementation</form:option>
<c:forEach items="${implementations.keySet()}" var="impl">
<form:option value="${impl}"><c:out value="${impl}" /></form:option>
</c:forEach>
</form:select>
</div>
<div style="display: none;" id="aaa">
<div class="input select">
<label for="aaa" >aaa<span class="small">Choose cluster</span></label>
<form:select id="cluster" name="cluster" path="cluster">
<form:option value="">Choose Cluster</form:option>
<c:forEach items="${implementations.get('aaa').getClusters().keySet()}" var="cl">
<form:option value="${cl}"><c:out value="${cl}" /></form:option>
</c:forEach>
</form:select>
<label >new</label>
<form:checkbox id="type" path="type" value="new" />
<label >old</label>
<form:checkbox id="type" path="type" value="old" />
<div style="display: none;" id="remote">
<label>Remote Sites <span class="small">Available Sites</span></label>
<c:if test="${implementations.get('aaa').getClusters().get(**<I need the above selected type checkbox value>**) == 'new'}">
<form:checkboxes items="${implementations.get('aaa').getRemoteSites().get('<I need the above selected type checkbox value>').get**<old | new from the type checkbox above>**Sites()}" path="remoteSites" id="remoteSites" style="display: block; float: right;" />
</c:if> </div>
<input style="margin-left: 150px; width: 125px; height: 30px;" class="button" type="submit" value="Add" />
<div class="spacer"></div>
</div>
</div>
</fieldset>
</form:form>
</body>
有什么帮助吗?
谢谢
I have trouble getting a form element value into a jstl tag. I am doing some fancy stuff in my jsp page, like I have a dropdown menu, once some value is chose, I load the rest of form and once that is chose I load rest, so for first dropdown I have no issues, because they are constants and I know what to load next, but the second drop down menu I have, has dynamic data from server, so I need to know what user selected, so I can load rest of form based on that.
I cant access that form element value in my jstl. how can I do that ?
my jsp:
<head>
<script type="text/javascript">
$(document).ready(function(){
$("#implementation").change(function(){
if ($(this).val() == "aaa" ) {
$("#aaa").slideDown("fast");
} else {
$("#aaa").slideUp("fast");
}
});
$("#type").change(function(){
if ($(this).val() == "new" || $(this).val() == "old") {
$("#remote").slideDown("fast");
} else {
$("#remote").slideUp("fast");
}
});
});
</script>
</head>
<body>
<form:form id="form" name="form" method="post" modelAttribute="store" action="/shard">
<fieldset>
<div class="input select">
<label for="implementation">Implementation<span class="small">Choose implementation</span></label>
<form:select name="implementation" path="implementation">
<form:option value="">Choose Implementation</form:option>
<c:forEach items="${implementations.keySet()}" var="impl">
<form:option value="${impl}"><c:out value="${impl}" /></form:option>
</c:forEach>
</form:select>
</div>
<div style="display: none;" id="aaa">
<div class="input select">
<label for="aaa" >aaa<span class="small">Choose cluster</span></label>
<form:select id="cluster" name="cluster" path="cluster">
<form:option value="">Choose Cluster</form:option>
<c:forEach items="${implementations.get('aaa').getClusters().keySet()}" var="cl">
<form:option value="${cl}"><c:out value="${cl}" /></form:option>
</c:forEach>
</form:select>
<label >new</label>
<form:checkbox id="type" path="type" value="new" />
<label >old</label>
<form:checkbox id="type" path="type" value="old" />
<div style="display: none;" id="remote">
<label>Remote Sites <span class="small">Available Sites</span></label>
<c:if test="${implementations.get('aaa').getClusters().get(**<I need the above selected type checkbox value>**) == 'new'}">
<form:checkboxes items="${implementations.get('aaa').getRemoteSites().get('<I need the above selected type checkbox value>').get**<old | new from the type checkbox above>**Sites()}" path="remoteSites" id="remoteSites" style="display: block; float: right;" />
</c:if> </div>
<input style="margin-left: 150px; width: 125px; height: 30px;" class="button" type="submit" value="Add" />
<div class="spacer"></div>
</div>
</div>
</fieldset>
</form:form>
</body>
any help ?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,“动态”值可能以某种方式连接到数据集或页面集,因此您应该了解需要获取的返回值。即使您没有,您也应该能够创建一些逻辑来根据用户选项获取选定的数据。
举例来说,我有一个下拉列表,其中包含基于数据库表中主键的选择值。选择该选项后,我只需根据下拉列表中的主键值从数据库中获取关联的数据集。下拉列表中的值可能是动态的,基于先前选择的选项,但它们仍然与特定数据集相关联。
这一切都可以通过通配符或一些自定义逻辑来完成,以解析您选择的选项服务器端。
Well, the "dynamic" values are likely somehow connected to a dataset or set of pages, so you should have an idea of the return value(s) you need to get. Even if you didn't you should be able to create some logic to fetch the selected data(s) based on user options.
Say for instance I have a dropdown list with selection values based on a primary key(s) from a database table. Once the option is selected, I simply fetch the associated data set from the database based on the primary key value in the dropdown. The values from the dropdown may be dynamic, based on previously selected options, but they are still tied to a specific dataset.
This can all be accomplished through wildcards or some custom logic to parse your select options server-side.