java - Validate a single field against a result from a service in Spring MVC -


i can't figure out how simple, 1-field validation check value against service (or other logic check).

most of form validation see uses class hold form data using javax.validation , marking attributes @notnull, @min(10), etc. , checking bindingresult.haserrors(). here: https://spring.io/guides/gs/validating-form-input/

i'm trying single field , want validate against service return me rather 1 of validation attributes.

what put in post handler in controller going?

this have in controller manage result form

@requestmapping(value = "/mycontroller", method=requestmethod.post) public string checkfieldval(@requestparam string valfromform){     if(!myservice.isthisvaluegood(valfromform)) {         //show user value bad     }     //return other page } 

and in jsp (something simple this):

<form id="form" method="post">     <label for="valuetocheck">what's value:</label>     <input type="text" id="valuetocheck" name="valuetocheck"></input>     <input type="submit" value="submit"> </form > 

try replace this:

 <form id="form" method="post"> 

with adding action this:

 <form action="mycontroller" id="form" method="post"> 

and replace this:

 @requestmapping(value = "/mycontroller", method=requestmethod.post)  public string checkfieldval(@requestparam string valfromform){ 

with adding right name:

  @requestmapping(value = "/mycontroller", method=requestmethod.post)   public string checkfieldval(@requestparam("valuetocheck") string valuetocheck){ 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -