1
votes

I'm developing a Liferay portlet using spring MVC. In the view part I have a dropdown field like that:

    <form:select path="addressUsage">
        <option>Home address</option>
        <option>Postal address</option>
    </form:select>

We know that in this case if the user select for example the first option so the value that the view will pass to the controller is "Home address" (in the attribute addressUsage of the corresponding class) But what I want is that the dropdown is displayed with "Home address" and "Postal address" options and what will pass to the controller is:

-> "HOME" in the case the user select "Home address" option.

-> "POSTAL" in the case the user select "Postal address" option

So I thought that I add a name attribute to the option tag. so the dropdown will be like that

    <form:select path="addressUsage">
        <option name="HOME">Home address</option>
        <option name="POSTAL">Postal address</option>
    </form:select>

So my question: is it possible to pass the name attribute of the corresponding selected option instead of the option text through the path attribute?

1

1 Answers

1
votes

I think what you're looking for is the value attribute.

<option value="HOME">Home address</option>, for example.

You can see here the value attribute of the option tag's Definition and Usage -

The value attribute specifies the value to be sent to a server when a form is submitted.

The content between the opening and closing tags is what the browsers will display in a drop-down list. However, the value of the value attribute is what will be sent to the server when a form is submitted.

Note: If the value attribute is not specified, the content will be passed as a value instead.