1

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>&nbsp;<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.

user2409128
  • 471
  • 1
  • 10
  • 21

1 Answers1

0

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.

Ankur Singhal
  • 26,012
  • 16
  • 82
  • 116