本文整理汇总了Java中org.springframework.binding.message.MessageContext.addMessage方法的典型用法代码示例。如果您正苦于以下问题:Java MessageContext.addMessage方法的具体用法?Java MessageContext.addMessage怎么用?Java MessageContext.addMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.binding.message.MessageContext
的用法示例。
在下文中一共展示了MessageContext.addMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateAdminForm
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
public void validateAdminForm(Person personBean, ValidationContext context) {
LOGGER.debug("Validate the admin - START");
MessageContext messages = context.getMessageContext();
if(personBean.getFirstName().equals(""))
messages.addMessage(new MessageBuilder().error().source("firstName").defaultText("required").build());
if(personBean.getLastName().equals(""))
messages.addMessage(new MessageBuilder().error().source("lastName").defaultText("required").build());
if(personBean.getEmail().equals(""))
messages.addMessage(new MessageBuilder().error().source("email").defaultText("required").build());
else
if(!testEmail(personBean.getEmail()))
messages.addMessage(new MessageBuilder().error().source("email").defaultText("incorrect form").build());
try {
if(BLPerson.getInstance().getByUsername(personBean.getUsername()) != null)
messages.addMessage(new MessageBuilder().error().source("username").defaultText("Username already exists!").build());
} catch (BusinessException e) {
e.printStackTrace();
}
LOGGER.debug("Validate the organisation - END");
}
示例2: validateCaptcha
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
public final String validateCaptcha(final RequestContext context, final Credential credential, final MessageContext messageContext){
final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
HttpSession session = request.getSession();
String rand = (String)session.getAttribute("rand");
session.removeAttribute("rand");
UsernamePasswordCaptchaCredential upc = (UsernamePasswordCaptchaCredential)credential;
String captcha = upc.getCaptcha();
System.out.println("获取Session验证码-->" + rand);
System.out.println("获取表单输入验证码-->" + captcha);
if(!StringUtils.hasText(rand) || !StringUtils.hasText(captcha)){
messageContext.addMessage(new MessageBuilder().error().code("required.captcha").build());
return "error";
}
if(captcha.equals(rand)){
return "success";
}
//这段网上这么写的messageContext.addMessage(new MessageBuilder().code("required.captcha").build());
//实际上这么写是org.springframework.binding.message.INFO级别的,这会导致前台表单无法显示这里的错误信息
messageContext.addMessage(new MessageBuilder().error().code("error.authentication.captcha.bad").build());
return "error";
}
示例3: handle
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
/**
* Maps an authentication exception onto a state name. Also sets an ERROR severity message in the message context.
*
* @param e Authentication error to handle.
* @param messageContext the spring message context
* @return Name of next flow state to transition to or {@value #UNKNOWN}
*/
public String handle(final Exception e, final MessageContext messageContext) {
if (e instanceof AuthenticationException) {
return handleAuthenticationException((AuthenticationException) e, messageContext);
}
if (e instanceof AbstractTicketException) {
return handleAbstractTicketException((AbstractTicketException) e, messageContext);
}
// we don't recognize this exception
LOGGER.trace("Unable to translate errors of the authentication exception [{}]"
+ "Returning [{}]", e, UNKNOWN);
final String messageCode = this.messageBundlePrefix + UNKNOWN;
messageContext.addMessage(new MessageBuilder().error().code(messageCode).build());
return UNKNOWN;
}
示例4: handleAuthenticationException
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
/**
* Maps an authentication exception onto a state name equal to the simple class name of the {@link
* AuthenticationException#getHandlerErrors()}
* with highest precedence. Also sets an ERROR severity message in the
* message context of the form {@code [messageBundlePrefix][exceptionClassSimpleName]}
* for for the first handler
* error that is configured. If no match is found, {@value #UNKNOWN} is returned.
*
* @param e Authentication error to handle.
* @param messageContext the spring message context
* @return Name of next flow state to transition to or {@value #UNKNOWN}
*/
protected String handleAuthenticationException(final AuthenticationException e,
final MessageContext messageContext) {
// find the first error in the error list that matches the handlerErrors
final String handlerErrorName = this.errors.stream().filter(e.getHandlerErrors().values()::contains)
.map(Class::getSimpleName).findFirst().orElseGet(() -> {
LOGGER.error("Unable to translate handler errors of the authentication exception [{}]"
+ "Returning [{}]", e, UNKNOWN);
return UNKNOWN;
});
// output message and return handlerErrorName
final String messageCode = this.messageBundlePrefix + handlerErrorName;
messageContext.addMessage(new MessageBuilder().error().code(messageCode).build());
return handlerErrorName;
}
示例5: handleAuthenticationTransactionAndGrantTicketGrantingTicket
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
/**
* Handle authentication transaction and grant ticket granting ticket.
*
* @param context the context
* @return the set
*/
protected Set<Event> handleAuthenticationTransactionAndGrantTicketGrantingTicket(final RequestContext context) {
try {
final Credential credential = getCredentialFromContext(context);
AuthenticationResultBuilder builder = WebUtils.getAuthenticationResultBuilder(context);
LOGGER.debug("Handling authentication transaction for credential [{}]", credential);
final Service service = WebUtils.getService(context);
builder = this.authenticationSystemSupport.handleAuthenticationTransaction(service, builder, credential);
LOGGER.debug("Issuing ticket-granting tickets for service [{}]", service);
return Collections.singleton(grantTicketGrantingTicketToAuthenticationResult(context, builder, service));
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
final MessageContext messageContext = context.getMessageContext();
messageContext.addMessage(new MessageBuilder().error()
.code(DEFAULT_MESSAGE_BUNDLE_PREFIX.concat(e.getClass().getSimpleName())).build());
return Collections.singleton(new EventFactorySupport().error(this));
}
}
示例6: validateDetails
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
public String validateDetails(UserBean userBean,MessageContext messageContext){
String status = "success";
log.info("Validation started");
if(userBean.getUserId().isEmpty()){
messageContext.addMessage(new MessageBuilder().error().source(
"userId").defaultText("UserId cannot be Empty").build());
log.info("Empty userid");
status = "failure";
}
if(userBean.getEmail().isEmpty()){
messageContext.addMessage(new MessageBuilder().error().source(
"email").defaultText("Email cannot be Empty").build());
log.info("Empty email");
status = "failure";
}
if(userBean.getAge()==null){
messageContext.addMessage(new MessageBuilder().error().source(
"age").defaultText("Age cannot be Empty").build());
log.info("Empty age");
status = "failure";
}
log.info("Validation was successful!");
return status;
}
示例7: validateDeliveryOptions
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
/**
* <p>validateDeliveryOptions</p>
*
* @param deliveryOptions a {@link org.opennms.reporting.core.DeliveryOptions} object.
* @param context a {@link org.springframework.binding.validation.ValidationContext} object.
*/
public void validateDeliveryOptions(DeliveryOptions deliveryOptions, ValidationContext context) {
MessageContext messages = context.getMessageContext();
if (!((deliveryOptions.getSendMail() | deliveryOptions.getPersist()))) {
messages.addMessage(new MessageBuilder().error().source("sendMail").
defaultText("one of send mail or persist should be selected").build());
messages.addMessage(new MessageBuilder().error().source("persist").
defaultText("one of send mail or persist should be selected").build());
} else {
if (deliveryOptions.getSendMail() && (deliveryOptions.getMailTo() == "")) {
messages.addMessage(new MessageBuilder().error().source("mailTo").
defaultText("cannot have empty mail recipient").build());
}
}
if (deliveryOptions.getInstanceId().length() == 0) {
messages.addMessage(new MessageBuilder().error().source("instanceId").
defaultText("cannot have an empty Id for the report instance").build());
} else if (m_reportSchedulerService.exists(deliveryOptions.getInstanceId())) {
messages.addMessage(new MessageBuilder().error().source("instanceId").
defaultText("report instanceId is already in use").build());
}
}
示例8: setConfirmationMessage
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
public void setConfirmationMessage(final ServiceExecutionResult<Person> serviceExecutionResult, final ReconciliationResult reconciliationResult, final MessageContext context) {
//if reconciliation result is EXACT or MAYBE then only a role was added, not a new person.
//a force add, would result in no reconciliationResult.
if (reconciliationResult != null){
if (reconciliationResult.getReconciliationType() == ReconciliationResult.ReconciliationType.EXACT ||
reconciliationResult.getReconciliationType() == ReconciliationResult.ReconciliationType.MAYBE) {
context.addMessage(new MessageBuilder().info().code("roleAdded").build());
return;
}
}
final Person person = serviceExecutionResult.getTargetObject();
final Identifier netId = person.getPrimaryIdentifiersByType().get(this.preferredPersonIdentifierType);
if (person.getCurrentActivationKey() != null) {
final MessageResolver message = new MessageBuilder().info().code("personAddedFinalConfirm").arg(netId.getValue()).arg(person.getCurrentActivationKey().asString()).build();
context.addMessage(message);
} else {
context.addMessage(new MessageBuilder().info().code("personAddedFinalConfirm").arg(netId.getValue()).arg("TempKey").build());
}
}
示例9: addWarningToContext
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
/**
* Adds a warning message to the message context.
*
* @param context Message context.
* @param warning Warning message.
*/
private static void addWarningToContext(final MessageContext context, final MessageDescriptor warning) {
final MessageBuilder builder = new MessageBuilder()
.warning()
.code(warning.getCode())
.defaultText(warning.getDefaultMessage())
.args(warning.getParams());
context.addMessage(builder.build());
}
示例10: addWarningToContext
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
/**
* Adds a warning message to the message context.
*
* @param context Message context.
* @param warning Warning message.
*/
private void addWarningToContext(final MessageContext context, final MessageDescriptor warning) {
final MessageBuilder builder = new MessageBuilder()
.warning()
.code(warning.getCode())
.defaultText(warning.getDefaultMessage())
.args(warning.getParams());
context.addMessage(builder.build());
}
示例11: validateCasMustChangePassView
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
/**
* Validate cas must change pass view.
*
* @param bean the bean
* @param context the context
*/
public void validateCasMustChangePassView(final PasswordChangeBean bean, final ValidationContext context) {
final MessageContext messages = context.getMessageContext();
if (!bean.getPassword().equals(bean.getConfirmedPassword())) {
messages.addMessage(new MessageBuilder().error().source("pm.passwordsMustMatch").
defaultText("Provided passwords do not match.").build());
return;
}
if (!bean.getPassword().matches(casProperties.getAuthn().getPm().getPolicyPattern())) {
messages.addMessage(new MessageBuilder().error().source("pm.passwordFailedCriteria").
defaultText("Password policy rejected the provided insecure password.").build());
}
}
示例12: addMessageDescriptorToMessageContext
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
/**
* Adds a warning message to the message context.
*
* @param context Message context.
* @param warning Warning message.
*/
protected static void addMessageDescriptorToMessageContext(final MessageContext context, final MessageDescriptor warning) {
final MessageBuilder builder = new MessageBuilder()
.warning()
.code(warning.getCode())
.defaultText(warning.getDefaultMessage())
.args((Object[]) warning.getParams());
context.addMessage(builder.build());
}
示例13: addWarningToContext
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
/**
* Adds a warning message to the message context.
*
* @param context Message context.
* @param warning Warning message.
*/
private void addWarningToContext(final MessageContext context, final Message warning) {
final MessageBuilder builder = new MessageBuilder()
.warning()
.code(warning.getCode())
.defaultText(warning.getDefaultMessage())
.args(warning.getParams());
context.addMessage(builder.build());
}
示例14: checkUser
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
public Event checkUser(LoginForm login, MessageContext messageContext) {
if (loginService.retrieveAccount(login.getUsername()) == null) {
MessageBuilder errorMessageBuilder1 = new MessageBuilder().error();
errorMessageBuilder1.source("username");
errorMessageBuilder1.code("login.username.error");
messageContext.addMessage(errorMessageBuilder1.build());
MessageBuilder errorMessageBuilder2 = new MessageBuilder().error();
errorMessageBuilder2.source("password");
errorMessageBuilder2.code("login.password.error");
messageContext.addMessage(errorMessageBuilder2.build());
return new EventFactorySupport().error(this);
}
return new EventFactorySupport().success(this);
}
示例15: addWarningToContext
import org.springframework.binding.message.MessageContext; //导入方法依赖的package包/类
/**
* Adds a warning message to the message context.
*
* @param context Message context.
* @param warning Warning message.
*/
private void addWarningToContext(final MessageContext context, final Message warning) {
final MessageBuilder builder = new MessageBuilder()
.warning()
.code(warning.getCode())
.defaultText(warning.getDefaultMessage())
.args(warning.getParams());
context.addMessage(builder.build());
this.hasWarningMessages = true;
}