Spring MVC 3 <form:Select> tag multiple selection
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.
You will need a correct equals
implementation in you Entities (especially in Channels
).
精彩评论