当前位置: 首页>>代码示例>>Java>>正文


Java MessageContext.addMessage方法代码示例

本文整理汇总了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");
}
 
开发者ID:CodeSphere,项目名称:termitaria,代码行数:27,代码来源:PersonBeanValidator.java

示例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";
}
 
开发者ID:v5java,项目名称:demo-cas-server-web,代码行数:25,代码来源:AuthenticationViaCaptchaFormAction.java

示例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;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:24,代码来源:AuthenticationExceptionHandlerAction.java

示例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;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:28,代码来源:AuthenticationExceptionHandlerAction.java

示例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));
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:26,代码来源:AbstractCasWebflowEventResolver.java

示例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;
}
 
开发者ID:mahendra-shinde,项目名称:web-flow-demos,代码行数:25,代码来源:DemoHandler.java

示例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());
    }
    
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:29,代码来源:DeliveryOptionsValidator.java

示例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());
    }
}
 
开发者ID:Jasig,项目名称:openregistry,代码行数:23,代码来源:PersonSearchAction.java

示例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());
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:AuthenticationViaFormAction.java

示例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());
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:AuthenticationViaFormAction.java

示例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());
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:20,代码来源:PasswordValidator.java

示例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());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:15,代码来源:AbstractCasWebflowEventResolver.java

示例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());
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:15,代码来源:AuthenticationViaFormAction.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Spring-MVC-Blueprints,代码行数:16,代码来源:CartController.java

示例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;
}
 
开发者ID:kevin3061,项目名称:cas-4.0.1,代码行数:16,代码来源:AuthenticationViaFormAction.java


注:本文中的org.springframework.binding.message.MessageContext.addMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。