2017-09-21 1 views
1

c'est mon exemple de code pour le cas de validation.but de haricot est sous forme déposée le message d'erreur est montre pascomment faire la validation des haricots

//controller class 
     @RequestMapping(value= "/offer.create", method=RequestMethod.POST) 
     public String doActions(@Valid @ModelAttribute ("offers") Offer offer, BindingResult result, 
       @RequestParam String action, Map<String, Object> map, 
       HttpServletRequest request){ 

     // 

      if(result.hasErrors()) { 
       /*map.put("offers", offerservice.getAlloffers()); 
       map.put("Offer", new Offer()); 
       map.put("SeasonTypes", new SeasonTypes()); 
       map.put("timeBased", new TimeBased()); 
       map.put("seasons", offerservice.getAllSeasons());*/ 
       System.out.println("inside the error section!!"); 
    //   System.out.println(merchantService.getAllMerchant().size()); 
       System.out.println("The error "+result); 

       return "create-offer"; 



      } 

// ------------ -------------------------------------------------- -------------- c'est la forme jsp

<div class="panel-group accordion" id="accordion" role="tablist" aria-multiselectable="true"> 
        <div class="panel panel-default red box"> 
         <div class="panel-heading" role="tab" id="heading-1"> 

           <h4 class="panel-title">Single Image</h4> 


         </div> 

          <div class="panel-body"> 
           <p>Upload or drag and drop image of your choice</p> 
                <div class="row"> 
                 <div class="col-md-12" style="margin-bottom:20px;width:100%;"> 
                  <form action="upload.image1" class="dropzone dropzone-mini" style="width:145px;" method="post" enctype="multipart/form-data"></form> 
                 </div> 
                </div> 


              <form:form action="offer.create" method="POST" commandName="Offer" id="formID" enctype="multipart/form-data"> 

                <div class="form-group"> 
                <label for="exampleInputEmail1"> Merchant Name</label> 
                <form:input path="offerHeading" class="form-control normtxtin" /> 
                <form:errors path="offers.*" cssClass="text-warning"></form:errors> 
                </div> 

                <div class="form-group"> 
                <label for="exampleInputEmail1"> Heading</label> 
                <form:input path="offerSubheading" class="form-control normtxtin" /> 
                <form:errors path="offers.*" cssClass="text-warning"></form:errors> 
                </div> 

                <div class="form-group"> 
                <label for="exampleInputEmail1">Description</label> 
                <form:textarea path="offerDescription" rows="5" cols="30" class="form-control normtxtin"/> 
                </div> 

                <div class="form-group"> 
                <label for="exampleInputEmail1">Issue Date</label> 
                <form:input path="issueDateTime" type="date" class="form-control normtxtin" placeholder="Select date"/> 
                </div> 

                <div class="form-group"> 
                <label for="exampleInputEmail1">Expiration Date</label> 
                <form:input path="expiryDate" type="date" class="form-control normtxtin" placeholder="Select date"/> 
                </div> 

                <div class="form-group"> 
                <label for="exampleInputEmail1">Offer Discount</label> 
                <form:input path="offerDiscount" class="form-control normtxtin" placeholder="offer Discount for the Entire offer"/> 
                </div> 

                <div class="form-group"> 
                <label for="exampleInputEmail1">Allocated points </label> 
                <form:input path="offerPrice" class="form-control normtxtin" /> 
                </div> 

                <div class="form-group"> 
                <label for="exampleInputEmail1">Offer Price</label> 
                <form:input path="pointsAllocated" class="form-control normtxtin" /> 
                </div> 

                <div class="form-group"> 
                <label for="exampleInputEmail1">offer Claim Limit</label> 
                <form:input path="offerClaimLimit" class="form-control normtxtin" /> 
                </div> 

                <div class="form-group"> 
                <label for="exampleInputEmail1">Available Branches</label> 

                <form:input path="offerAvailableBranches" class="form-control normtxtin" placeholder="Add branches seperated by a ',' Ex: galle, colombo, Kandy" /> 
                </div> 

                <div class="col-md-6"></div> 
                <div class="col-md-6"> 
                 <button type="submit" class="btn btn-primary" style="width:100%;font-size:16px;padding:10px;" name="action" value="Add">Create Offer</button> 
                </div> 
               </form:form> 
         </div> 
         </div> 

c'est la classe modèle

public class Offer implements java.io.Serializable { 

    private long offerid; 
    private Merchant merchant; 
    private MerchantUser merchantUserByAddedByRef; 
    private MerchantUser merchantUserByLastModifiedByRef; 
    private String issueDateTime; 
    private BigDecimal pointsAllocated; 
    private String expiryDate; 
    private String offerHeading; 
    @NotEmpty 
    private String offerSubheading; 
    @NotEmpty 
    private String offerDescription; 
    private String offerFilterTypes; 
    private String videoUrl; 

ceci est le fichier message.property

NotEmpty.Offer.offerSubheading = Heading field can't be Empty! 
NotEmpty.Offer.offerDescription = Heading field can't be Empty! 

ici dans la page jsp, après cliquant sur le bouton apparaît form.when pertinent après avoir fait la validation si leur a une erreur, il rediriger vers la page jsp alors ne devrait pas avoir que forme here.because de cette forme apparaîtra seulement après cliquage .donc que msg d'erreur ne peut pas montré

images suivantes sont que .jsp vue .jsp page view before press single image buttonafter click that single image button

+0

Désolé - y a-t-il une question ici quelque chose? –

+0

oui c'est. J'ai besoin de rediriger le formulaire. mais ici ne pas rediriger ce formulaire après avec une erreur de validation. ci-dessus lien afficher la page jsp j'ai besoin de rediriger l'image qui apparaît dans le 2ème lien [2] pas [1] [1] jsp vue de la page avant appuyez sur le bouton image unique [2] après cliquez sur ce bouton image unique – kaushi

Répondre

0

finalement je l'ai fait mon travail le problème était @ModelAttribute ("offres") ---> offres et commandName = "De fer "ne sont pas correspondre les uns aux autres :)