How to implement a DataList component in Spring MVC -
i'm working on webapp , wonder if there's chance implement following html element in spring mvc?
<input list="browsers"> <datalist id="browsers"> <option value="internet explorer"> <option value="firefox"> <option value="chrome"> <option value="opera"> <option value="safari"> </datalist>
thanks in advance!
you can whatever want on jsp pages.
for example:
<form:form method="post" commandname="recipe" action="${home}/admin/recipes"> <div class="form-group"> <label><s:message code="recipe.title" />*</label> <form:input path="title" cssclass="form-control" /> <form:errors path="title" cssclass="error-help" /> </div> <div class="form-group"> <s:message code="add" var="addlabel" /> <input type="submit" class="btn btn-success" value="${addlabel}" /> </div> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <span class="glyphicon glyphicon-envelope"></span> </span> <input class="form-control" list="datalist" name="data" required placeholder="<s:message code='user.email' />" value="${useremail}" /> <datalist id="datalist"> <option value="first" /> <option value="second" /> </datalist> </div> </div> </form:form>
here have model object "recipe" field "title" , field "data" datalist
controller code:
@requestmapping(value = "/admin/recipes", method = requestmethod.post) public string add( @modelattribute("recipe") @valid recipe recipe, bindingresult bindingresult, @requestparam("data") string data, model model) { if (bindingresult.haserrors()) { populateeditform(model, recipe); return "admin:/recipes/add"; } system.out.println(data); recipe = recipeservice.create(recipe); return "redirect:/admin/recipes/" + recipe.getid(); }
you can choose "first" or "second" "data" input , printed out on server-side
Comments
Post a Comment