Results 1 to 4 of 4

Thread: spring webflow 2 binding: how to populate <select> with enum values

  1. #1
    Join Date
    May 2012
    Posts
    6

    Default spring webflow 2 binding: how to populate <select> with enum values

    I'm working with spring webflow 2 and I'm facing the issue of presenting a form for user registration. The user has to insert name, surname... and his/her nationality. This is the model class:

    Code:
    @Component
        @Entity
        @Table (name = "personal_data")
        public class PersonalData implements Serializable {
    
    @Id @GeneratedValue
    @Column (name = "id")
    private Integer id;
    
    @Column (name = "name", nullable=false)
    private String name;
    
    @Column (name = "familyName", nullable=false)
    private String familyName;
    
    @Column (name = "nationality")
    @Enumerated (EnumType.STRING)
    private Nationality nationality;
    
        //getters and setters
        }
    Where Nationality is:
    
    public enum Nationality {
        Afghan, Albanian , Algerian , American , Andorran , Angolan , Antiguans , Argentinean , Armenian ...
    }
    I can bind everything with spring webflow and the form is showing properly. But I can't fill up the tag

    The jsp is:

    Code:
    <tr>
                <td><spring:message code="label.familyName"/>:</td>
                <td><form:input path="personalData.familyName" /> <form:errors path="personalData.familyName"/> </td>
            </tr>
    
                <td><spring:message code="label.name"/>:</td>
                <td><form:input path="personalData.name" /> <form:errors path="personalData.name"/> </td>
            </tr>
    
                <td><spring:message code="label.nationality"/>:</td>
                <td><form:select path="personalData.nationality"/> <form:errors path="personalData.nationality"/>
    
                    </td>
            </tr>
    And the spring webflow is defined as:

    Code:
     <var name="profile" class="com.tclouds.tpaas.models.user.UserProfile"/>
    
        <view-state id="registerProfile" view="profile/create1" model="profile">
            <transition on="submitRegistration" to="confirmData"/>
        </view-state>
    Can you please tell me how can I populate the

    many thanks

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    You have a select a select needs items (I suggest a read of the reference guide). Simply make an array/list of all Nationality options and add that as model data so you can use it for rendering it.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    May 2012
    Posts
    6

    Default

    Quote Originally Posted by Marten Deinum View Post
    You have a select a select needs items (I suggest a read of the reference guide). Simply make an array/list of all Nationality options and add that as model data so you can use it for rendering it.
    thanks Merten for the quick reply. I've actually thought at that solution but... how can I attach an other model to the view? I mean, with this:
    Code:
    <view-state id="registerProfile" view="profile/create1" model="profile">
            <transition on="submitRegistration" to="confirmData"/>
        </view-state>
    I'm binding the object called "profile"

    But how can I add another object (the nationality list) as well? Do I have to embed it into profile?

    Thanks in advance.

    Marco

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    I strongly suggest a read of the reference guide and sample applications...

    There is a difference between your form object (your profile) and reference data (data needed to render the form like collections to fill a drop downbox). As stated simply add a list or array and use that as the items for the select tag.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •