I am using unordered list to make dropdown. I want to select some value from drop down list and want to use it in controller. Basically I should do this using <form:select>
but it is now vary difficult to implement. Other part are ok and i am able to use them in controller but how to get the value from list i don't know.
I have implemented html code like this
<form role="form" method="post" action="/Web/password.html">
<fieldset>
<div class="form-group input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-user"></i>
</span>
<input class="form-control" placeholder="User Name" name="userName" type="email" required="" autofocus="">
</div>
<div class="form-group input-group">
<span class="input-group-addon">Applications</i></span>
<div class="btn-group" id='btnn'>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span data-bind="label">Select One Application</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" name="dropDown" role="menu" style="height:200px;overflow: auto;" >
<c:forEach var ="entry" items="${listOfApp }">
<li><a tabindex="-1" href=""><c:out value="${entry }" /></a></li>
</c:forEach>
</ul>
</div>
</div>
</fieldset>
</form>
and my controller is
@RequestMapping(value = "/password.html", method = RequestMethod.POST)
public String submit(@RequestParam (value ="userName") String userName,
@RequestParam ("dropDown") String dropDown) {
System.out.println(entry+" "+userName);
return "Hi";
}
Is it correct method method to get value from dropdown using @requestParam as i did in this. If it is wrong then can someone tell what is the correct way to do that.
Few Things:-
1.) At first place this could have been handled with Spring
itself, if proper commandName
have been used, Spring
would have mapped it.
2.) Trigger some event on change of a dropdown, add it in javascript/jquery, have a hidden field,
and onChange
of dropdown option, your event should get triggered, and set the value of selected option into hidden field
. use this hidden field in your controller.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.