2

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:

    @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:

<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:

    <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

1

1 Answer 1

4

"items" attribute in <form:options /> tag shows the following documentation:

The Collection, Map or array of objects used to generate the inner 'option' tags. This attribute is required unless the containing select's property for data binding is an Enum, in which case the enum's values are used.

So you just have to add the <form:options /> tag without any attribute inside the select. That will make the select get filled with the enumeration items as texts and values. You also can add a default "choose" option. For example:

<form:select path="personalData.nationality">
    <option value="">Choose a nationality</option>
    <form:options />
</form:select>

That code will produce the following html output:

<select name="personalData.nationality">
    <option value="">Choose a nationality</option>
    <option value="Afghan">Afghan</option>
    <option value="Albanian">Albanian</option>
    <option value="Algerian">Algerian</option>
    <option value="American">American</option>
    <option value="Andorran">Andorran</option>
    <option value="Angolan">Angolan</option>
    <option value="Antiguans">Antiguans</option>
    <option value="Argentinean">Argentinean</option>
    <option value="Armenian">Armenian</option>
</select>

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.