How to map dropdown from Spring form to one to many entities?

946 views Asked by At

I have two entities like below, and in my JSP page the drop down code is written, and i'm unable to map fields from Spring form to SecondarySkill through OneToMany scenario.

Please suggest how could i map the below drop down to SecondarySkill entity skill name.

java code:

public class Requisition {
    //some fields
    @OneToMany(cascade=CascadeType.ALL,mappedBy="req")   
    private Set<SecondarySkill> secSkill;

    //setters and getters
}

public class SecondarySkill{

    private int id;
    private String skillName;

    @ManyToOne
    @JoinColumn(name="req_id")
    Requisition req;

    //setters and getters
}
                

JSP code:

<label for="exampleInputEmail1">Secondary Skill:
<span style="color: red">*</span></label>
<form:select class="form-control" multiple="multiple" path="rpd" id="secSkillId">                                                 

    <option value="0">--Select--</option>
    <option value="1">JAVA</option>
    <option value="2">.Net</option>
    <option value="3">PHP</option>

</form:select>
1

There are 1 answers

1
Roman C On

You can use form:options to populate your options collection.

<form:select class="form-control" multiple="multiple" path="rpd" id="secSkillId">                                                     
    <option value="0">--Select--</option>
    <form:options items="${secSkill}" itemValue="id" itemLabel="skillName"/>    
</form:select>