I am using a dropdown list in JSP of spring MVC like this
<form:select path="isConfirmed">
<form:option value="1">Yes</form:option>
<form:option value="2">No</form:option>
</form:select>
when the user selects any option(e.g Yes) and click save button the corresponding value(e.g. 1) saved in database.Now in another JSP form I need to retrieve this user choice, but I am able to show only value(e.g. 1). But all I want to show option name like "Yes" in this case. Is there any way I can do this? Thanks in advance
There are two ways to do it:
a. The simplest way is to change the value of the option to the name in select:
<form:select path="isConfirmed">
<form:option value="Yes">Yes</form:option>
<form:option value="No">No</form:option>
</form:select>
In your case it's to change the value from 1,2
to Yes,No
,then it can show in other JSP pages.
b. Don't modify the select code,instead you need to query the option detail (or calculate it)before you show another jsp page:
@RequestMapping("showAnotherPage")
public String anotherJSP(String value,Model model){
SelecteMOdel sModel = modelService.findById(value);//query the detail infomation of selected value
model.addAttribute("selectedModel",sModel);
return "other.jsp";
}