简体   繁体   English

Spring MVC 3 <form:Select> 标记多个选择

[英]Spring MVC 3 <form:Select> tag multiple selection

I need to select multiple values in the multiple selection form:select tag. 我需要在多选形式中选择多个值:select tag。 my jsp code is 我的jsp代码是

<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. 实际上,我有3个表 - > ServiceRegistration,Channels(包含META数据)和ServiceChannel。 ServiceChannel contains foreign key reference with both serviceregistration and channel tables. ServiceChannel包含具有serviceregistration和channel表的外键引用。 So, one serviceid may have multiple channelid's mapped in the servicechannel table. 因此,一个serviceid可能在servicechannel表中映射了多个channelid。

my ServiceRegistration.java entity class has the channelsInvolved field as... 我的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 entity class... Channels.java Channel实体类... Channels.java

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column private int channelid;
@Column private String channelname; 

ServiceChannel.java entity class... 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;

Say, I have a service id >> 2 mapped to channelid >> 1 and 2. I am able see 2 records in the "channelsInvolved". 说,我有一个服务ID >> 2映射到channelid >> 1和2.我可以在“channelsInvolved”中看到2条记录。 But when I set the serRegistration as model attribute to the jsp, none is selected in the select tag. 但是当我将serRegistration设置为jsp的model属性时,select选项中没有选择任何一个。

help appreciated, Thanks. 帮助表示感谢,谢谢。

您将需要在实体中实现正确的equals实现(特别是在Channels )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM