Spring MVC 3<形式 :选择>标签多选形式>
我需要在多重选择表单中选择多个值:选择标签。我的jsp代码是
<form:form id="myForm"
action="service.do" modelAttribute="services"
method="POST">
....
....
<form:select path="channelsInvolved" items="${allChannels}" itemValue="channelid" itemLabel="channelname">
我的控制器是...
List<Channels> channels = dao.getAllChannels();
model.addAttribute("allChannels", channels);
ServiceRegistration serRegistration = dao.getById(2);
model.put("services", serRegistration);
实际上,我有3个表-> ServiceRegistration、Channels(包含 META 数据)和 ServiceChannel。 ServiceChannel 包含服务注册和通道表的外键引用。因此,一个serviceid可以在servicechannel表中映射多个channelid。
我的 ServiceRegistration.java 实体类具有 ChannelsInvolved 字段作为...
@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.EAGER)
@JoinTable(name = "ServiceChannel", joinColumns = {
@JoinColumn(name="serviceid", unique = true)
},
inverseJoinColumns = {
@JoinColumn(name="channelid")
}
)
private List<Channels> channelsInvolved;
public List<Channels> getChannelsInvolved() {
return channelsInvolved;
}
public void setChannelsInvolved(List<Channels> channelsInvolved) {
this.channelsInvolved = channelsInvolved;
}
Channel 实体类... Channels.java
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column private int channelid;
@Column private String channelname;
ServiceChannel.java 实体类...
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column private int servicechannelid;
@ManyToOne
@JoinColumn(name = "serviceid")
private ServiceRegistration serviceRegistration;
@ManyToOne
@JoinColumn(name = "channelid")
private Channels channels;
比如说,我有一个服务 id >>> 2 映射到channelid>> 1和2。我可以在“channelsInvolved”中看到2条记录。但是当我将 serRegistration 设置为 jsp 的模型属性时,选择标记中没有选择任何一个。
帮助表示赞赏,谢谢。
I need to select multiple values in the multiple selection form:select tag. my jsp code is
<form:form id="myForm"
action="service.do" modelAttribute="services"
method="POST">
....
....
<form:select path="channelsInvolved" items="${allChannels}" itemValue="channelid" itemLabel="channelname">
my controller is...
List<Channels> channels = dao.getAllChannels();
model.addAttribute("allChannels", channels);
ServiceRegistration serRegistration = dao.getById(2);
model.put("services", serRegistration);
Actually, I have 3 tables -> ServiceRegistration, Channels (contains META data) and ServiceChannel. ServiceChannel contains foreign key reference with both serviceregistration and channel tables. So, one serviceid may have multiple channelid's mapped in the servicechannel table.
my ServiceRegistration.java entity class has the channelsInvolved field as...
@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.EAGER)
@JoinTable(name = "ServiceChannel", joinColumns = {
@JoinColumn(name="serviceid", unique = true)
},
inverseJoinColumns = {
@JoinColumn(name="channelid")
}
)
private List<Channels> channelsInvolved;
public List<Channels> getChannelsInvolved() {
return channelsInvolved;
}
public void setChannelsInvolved(List<Channels> channelsInvolved) {
this.channelsInvolved = channelsInvolved;
}
Channel entity class... Channels.java
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column private int channelid;
@Column private String channelname;
ServiceChannel.java entity class...
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column private int servicechannelid;
@ManyToOne
@JoinColumn(name = "serviceid")
private ServiceRegistration serviceRegistration;
@ManyToOne
@JoinColumn(name = "channelid")
private Channels channels;
Say, I have a service id >> 2 mapped to channelid >> 1 and 2. I am able see 2 records in the "channelsInvolved". But when I set the serRegistration as model attribute to the jsp, none is selected in the select tag.
help appreciated, Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要在实体中(尤其是在通道中)正确实现
equals
。You will need a correct
equals
implementation in you Entities (especially inChannels
).