本文整理汇总了Java中org.springframework.validation.BindingResult.getTarget方法的典型用法代码示例。如果您正苦于以下问题:Java BindingResult.getTarget方法的具体用法?Java BindingResult.getTarget怎么用?Java BindingResult.getTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.validation.BindingResult
的用法示例。
在下文中一共展示了BindingResult.getTarget方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeBindingResultIfNecessary
import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
private void removeBindingResultIfNecessary(Object key, Object value) {
if (key instanceof String) {
String attributeName = (String) key;
if (!attributeName.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + attributeName;
BindingResult bindingResult = (BindingResult) get(bindingResultKey);
if (bindingResult != null && bindingResult.getTarget() != value) {
remove(bindingResultKey);
}
}
}
}
示例2: save
import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
/**
* Save element to database
*
* @param type
* the domain type
* @param request
* current HttpServletRequest
* @param page
* current page
* @param size
* current page size
* @param model
* current model
*
* @return edit/view template name
*/
@RequestMapping(value = "${crudadmin.url}/post/{type}/{size}/{page}", method = RequestMethod.POST)
public String save(@PathVariable String type, @PathVariable int size, @PathVariable int page,
HttpServletRequest request, Model model) {
try {
CrudAdminRepository repoAdmin = repositoryMap.get(type);
ServletRequestParameterPropertyValues values = new ServletRequestParameterPropertyValues(request);
final BindingResult result = repoAdmin.getWebDataBinder(values).getBindingResult();
Object object = result.getTarget();
String idString = values.getPropertyValue("id").getValue().toString();
idString = idString.isEmpty() ? null : idString;
Object id = null;
try {
// existing object ?
if (idString != null) {
id = idSerializer.fromString(idString, repoAdmin.getIdType());
repoAdmin.getId().set(object, id);
}
// save
repoAdmin.getRepositoryObjectSerializable().save(object);
idString = getStringFromId(repoAdmin.getId().get(object), repoAdmin);
return "redirect:/" + crudAdminProperties.getUrl() + "/view/" + repoAdmin.getDomainTypeNameLowerCase()
+ "/" + size + "/" + page + "/" + idString+'/';
} catch (Exception transactionException) {
Throwable rootCause = transactionException;
while (rootCause.getCause() != null) {
rootCause = rootCause.getCause();
}
if (rootCause instanceof ConstraintViolationException) {
ConstraintViolationException constraintViolationException = (ConstraintViolationException) rootCause;
String message = "";
for (ConstraintViolation<?> constraintValidation : constraintViolationException
.getConstraintViolations()) {
message += "<br/><b>" + constraintValidation.getPropertyPath().toString() + "</b> "
+ constraintValidation.getMessage();
}
return doEdit(type, idString, size, page, message, model);
}
throw transactionException;
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}