本文整理汇总了Java中com.opensymphony.xwork2.ModelDriven类的典型用法代码示例。如果您正苦于以下问题:Java ModelDriven类的具体用法?Java ModelDriven怎么用?Java ModelDriven使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ModelDriven类属于com.opensymphony.xwork2包,在下文中一共展示了ModelDriven类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intercept
import com.opensymphony.xwork2.ModelDriven; //导入依赖的package包/类
@Override
public String intercept(ActionInvocation invocation) throws Exception {
Object action = invocation.getAction();
if (action instanceof ModelDriven) {
ModelDriven modelDriven = (ModelDriven) action;
ValueStack stack = invocation.getStack();
Object model = modelDriven.getModel();
if (model != null) {
stack.push(model);
}
if (refreshModelBeforeResult) {
invocation.addPreResultListener(new RefreshModelBeforeResult(modelDriven, model));
}
}
return invocation.invoke();
}
示例2: performBeanValidation
import com.opensymphony.xwork2.ModelDriven; //导入依赖的package包/类
@SuppressWarnings("nls")
protected void performBeanValidation(Object action, Validator validator) {
LOG.debug("Initiating bean validation..");
Set<ConstraintViolation<Object>> constraintViolations;
if (action instanceof ModelDriven) {
LOG.debug("Performing validation on model..");
constraintViolations = validator.validate(((ModelDriven) action).getModel());
} else {
LOG.debug("Performing validation on action..");
constraintViolations = validator.validate(action);
}
addBeanValidationErrors(constraintViolations, action);
}
示例3: addBeanValidationErrors
import com.opensymphony.xwork2.ModelDriven; //导入依赖的package包/类
@SuppressWarnings("nls")
private void addBeanValidationErrors(Set<ConstraintViolation<Object>> constraintViolations, Object action) {
if (constraintViolations != null) {
ValidatorContext validatorContext = new DelegatingValidatorContext(action);
for (ConstraintViolation<Object> constraintViolation : constraintViolations) {
String key = constraintViolation.getMessage();
String message = key;
try {
message = validatorContext.getText(key);
if(convertToUtf8 && StringUtils.isNotBlank(message)) {
message = new String(message.getBytes(convertFromEncoding), "UTF-8");
}
} catch (Exception e) {
LOG.error("Error while trying to fetch message", e);
}
if (isActionError(constraintViolation)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding action error '#0'", message);
}
validatorContext.addActionError(message);
} else {
ValidationError validationError = buildBeanValidationError(constraintViolation, message);
String fieldName = validationError.getFieldName();
if (action instanceof ModelDriven && fieldName.startsWith(ValidatorConstants.MODELDRIVEN_PREFIX)) {
fieldName = fieldName.replace("model.", ValidatorConstants.EMPTY_SPACE);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Adding field error [#0] with message '#1'", fieldName, validationError.getMessage());
}
validatorContext.addFieldError(fieldName, validationError.getMessage());
}
}
}
}
示例4: RefreshModelBeforeResult
import com.opensymphony.xwork2.ModelDriven; //导入依赖的package包/类
public RefreshModelBeforeResult(ModelDriven action, Object model) {
this.originalModel = model;
this.action = action;
}