Search code examples
formsjspbundlehtml-select

how to internationalize <form:option /> values for a <form:select /> in jsp?


Please, mind the code snippet bellow:

        <form:select path="type">
            <form:option value="national"><s:message code="holiday-list-type1" /></form:option>
            <form:option value="state"><s:message code="holiday-list-type2" /></form:option>
            <form:option value="city"><s:message code="holiday-list-type3" /></form:option>
            <form:option value="other"><s:message code="holiday-list-type4" /></form:option>
        </form:select>

I'd like the value for each <form:option ... /> to have a value defined in the bundle, instead of being hard-coded on the JSP.

How can I do so? Thanks in advance!


Solution

  • I got it working by doing the following:

    <form:select path="type">
        <form:option value="holiday-list-type1"><s:message code="holiday-list-type1" /></form:option>
        <form:option value="holiday-list-type2"><s:message code="holiday-list-type2" /></form:option>
        <form:option value="holiday-list-type3"><s:message code="holiday-list-type3" /></form:option>
        <form:option value="holiday-list-type4"><s:message code="holiday-list-type4" /></form:option>
    </form:select>
    

    This way I persist the value holiday-list-type{1-4} (which is the key to my messages bundle) to the database and the JSP returns the internationalized value.

    Hope this helps someone too! :)