使用 spring mvc 跟踪多个相关的输入框

发布于 2024-08-15 06:01:48 字数 797 浏览 4 评论 0原文

我们有一个需要在 html 页面上编辑的域对象列表。例如,命令 &域对象:

class MyCommand {
    List<Person> persons;
}

class Person {
    String fname;
    String lname;
}

然后,我期望由 Spring MVC 标签库生成的 HTML 是这样的:

<form>
   <input name="persons[0].fname">&nbsp;<input name="persons[0].lname"><br/>
   <input name="persons[1].fname">&nbsp;<input name="persons[1].lname"><br/>
   <input name="persons[2].fname">&nbsp;<input name="persons[2].lname"><br/>
   ...
   <input name="persons[n].fname">&nbsp;<input name="persons[n].lname"><br/>
</form>

但看不到如何使用 Spring 表单标签库(使用 Spring 2.5.6)来表达它。 )。我想使用标签库,以便它负责将现有值绑定到标签以进行编辑(当它们存在时)。

有什么建议吗?

we have a list of domain objects needing to be edited on an html page. For example, the command & domain objects:

class MyCommand {
    List<Person> persons;
}

class Person {
    String fname;
    String lname;
}

Then, the HTML I expect to have the Spring MVC tag libraries generate is like this:

<form>
   <input name="persons[0].fname"> <input name="persons[0].lname"><br/>
   <input name="persons[1].fname"> <input name="persons[1].lname"><br/>
   <input name="persons[2].fname"> <input name="persons[2].lname"><br/>
   ...
   <input name="persons[n].fname"> <input name="persons[n].lname"><br/>
</form>

But can't see how to express this using the Spring Form Tag Libraries (using Spring 2.5.6.). I want to use the tag libraries so that it takes care of binding existing values to the tags for editing (when they're there).

Any tips?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦魇绽荼蘼 2024-08-22 06:01:48

没有一种方法可以简单地让 Spring 表单标签基于集合生成整个列表(它将针对选择框中的选项执行此操作,但这是我所知道的唯一基于集合的扩展)。但是,您仍然可以在循环中使用 Spring 表单标签,如下所示:

<c:forEach var="person" varStatus="loopStatus" items="myCommand.persons">
   <form:input path="persons[${loopStatus.index}].fname" /> <form:input path="persons[${loopStatus.index}].lname" /><br />
</c:forEach>

There isn't a way to simply have the Spring Form Tags generate the whole list based on the collection (it will do this for the options in a select box, but that's the only collection-based expansion I'm aware of). However, you can still use the Spring Form Tags within a loop like so:

<c:forEach var="person" varStatus="loopStatus" items="myCommand.persons">
   <form:input path="persons[${loopStatus.index}].fname" /> <form:input path="persons[${loopStatus.index}].lname" /><br />
</c:forEach>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文