1
这是我的豆validation.but情况下的代码示例是形式提交的错误信息没有显示如何做Bean验证
//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";
}
// ------------ -------------------------------------------------- -------------- 这是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>
这是模型类
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;
这是message.property文件
NotEmpty.Offer.offerSubheading = Heading field can't be Empty!
NotEmpty.Offer.offerDescription = Heading field can't be Empty!
在这里jsp页面,点击后按钮将在进行验证后会出现相关form.when,如果他们有一些错误重定向到jsp页面然后不应该有这种形式的形式here.because后,才按一下按钮。所以这个错误味精不能显示
以下图片看来,.JSP视图.jsp page view before press single image buttonafter click that single image button
对不起 - 有问题吗? –
是的。我需要重定向表单。但是在发生验证错误后,此处不会重定向该表单。上面的链接显示的jsp页面我需要重定向图像显示在第二链接[2]不是[1] [1] jsp页面视图之前按下单个图像按钮[2]后单击该单个图像按钮 – kaushi