Java Code Examples for javax.faces.application.FacesMessage#setSeverity()

The following examples show how to use javax.faces.application.FacesMessage#setSeverity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Registration.java    From CargoTracker-J12015 with MIT License 6 votes vote down vote up
public String register() {
    String trackingId = null;

    try {
        if (!originUnlocode.equals(destinationUnlocode)) {
            trackingId = bookingServiceFacade.bookNewCargo(
                    originUnlocode,
                    destinationUnlocode,
                    new SimpleDateFormat(FORMAT).parse(arrivalDeadline));
        } else {
            // TODO See if this can be injected.
            FacesContext context = FacesContext.getCurrentInstance();
            FacesMessage message = new FacesMessage(
                    "Origin and destination cannot be the same.");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            context.addMessage(null, message);
            return null;
        }
    } catch (ParseException e) {
        throw new RuntimeException("Error parsing date", e);
    }

    return "show.xhtml?faces-redirect=true&trackingId=" + trackingId;
}
 
Example 2
Source File: Track.java    From pragmatic-microservices-lab with MIT License 6 votes vote down vote up
public void onTrackById() {

        markersModel = new DefaultMapModel();

        Cargo cargo = cargoRepository.find(new TrackingId(trackingId));

        if (cargo != null) {
            List<HandlingEvent> handlingEvents = handlingEventRepository
                    .lookupHandlingHistoryOfCargo(new TrackingId(trackingId))
                    .getDistinctEventsByCompletionTime();
            this.cargo = new CargoTrackingViewAdapter(cargo, handlingEvents);
            this.destinationCoordinates = net.java.cargotracker.application.util.LocationUtil.getPortCoordinates(cargo.getRouteSpecification().getDestination().getUnLocode().getIdString());

        } else {
            // TODO See if this can be injected.
            FacesContext context = FacesContext.getCurrentInstance();
            FacesMessage message = new FacesMessage(
                    "Cargo with tracking ID: " + trackingId + " not found.");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            context.addMessage(null, message);
            this.cargo = null;
        }
    }
 
Example 3
Source File: PasswordValidator.java    From oxTrust with MIT License 6 votes vote down vote up
@Override
public void validate(FacesContext arg0, UIComponent arg1, Object value) throws ValidatorException {
	if (attributeService == null) {
		attributeService = CdiUtil.bean(AttributeService.class);
	}
	GluuAttribute attributeByName = attributeService.getAttributeByName(USER_PASSWORD);
	AttributeValidation validation = attributeByName.getAttributeValidation();
	if (validation != null && validation.getRegexp() != null && !validation.getRegexp().isEmpty()) {
		pattern = Pattern.compile(validation.getRegexp());
		hasValidation = true;
	}
	if (hasValidation) {
		matcher = pattern.matcher(value.toString());
	}
	if (hasValidation && !matcher.matches()) {
		FacesMessage msg = new FacesMessage(
				facesMessages.evalResourceAsString("#{msg['password.validation.invalid']}"));
		msg.setSeverity(FacesMessage.SEVERITY_ERROR);
		throw new ValidatorException(msg);

	}
}
 
Example 4
Source File: Track.java    From pragmatic-microservices-lab with MIT License 6 votes vote down vote up
public void onTrackById() {

        markersModel = new DefaultMapModel();

        Cargo cargo = cargoRepository.find(new TrackingId(trackingId));

        if (cargo != null) {
            List<HandlingEvent> handlingEvents = handlingEventRepository
                    .lookupHandlingHistoryOfCargo(new TrackingId(trackingId))
                    .getDistinctEventsByCompletionTime();
            this.cargo = new CargoTrackingViewAdapter(cargo, handlingEvents);
            this.destinationCoordinates = net.java.cargotracker.application.util.LocationUtil.getPortCoordinates(cargo.getRouteSpecification().getDestination().getUnLocode().getIdString());

        } else {
            // TODO See if this can be injected.
            FacesContext context = FacesContext.getCurrentInstance();
            FacesMessage message = new FacesMessage(
                    "Cargo with tracking ID: " + trackingId + " not found.");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            context.addMessage(null, message);
            this.cargo = null;
        }
    }
 
Example 5
Source File: Track.java    From pragmatic-microservices-lab with MIT License 6 votes vote down vote up
public void onTrackById() {

        markersModel = new DefaultMapModel();

        Cargo cargo = cargoRepository.find(new TrackingId(trackingId));

        if (cargo != null) {
            List<HandlingEvent> handlingEvents = handlingEventRepository
                    .lookupHandlingHistoryOfCargo(new TrackingId(trackingId))
                    .getDistinctEventsByCompletionTime();
            this.cargo = new CargoTrackingViewAdapter(cargo, handlingEvents);
            this.destinationCoordinates = net.java.cargotracker.application.util.LocationUtil.getPortCoordinates(cargo.getRouteSpecification().getDestination().getUnLocode().getIdString());

        } else {
            // TODO See if this can be injected.
            FacesContext context = FacesContext.getCurrentInstance();
            FacesMessage message = new FacesMessage(
                    "Cargo with tracking ID: " + trackingId + " not found.");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            context.addMessage(null, message);
            this.cargo = null;
        }
    }
 
Example 6
Source File: Track.java    From pragmatic-microservices-lab with MIT License 6 votes vote down vote up
public void onTrackById() {

        markersModel = new DefaultMapModel();

        Cargo cargo = cargoRepository.find(new TrackingId(trackingId));

        if (cargo != null) {
            List<HandlingEvent> handlingEvents = handlingEventRepository
                    .lookupHandlingHistoryOfCargo(new TrackingId(trackingId))
                    .getDistinctEventsByCompletionTime();
            this.cargo = new CargoTrackingViewAdapter(cargo, handlingEvents);
            this.destinationCoordinates = net.java.cargotracker.application.util.LocationUtil.getPortCoordinates(cargo.getRouteSpecification().getDestination().getUnLocode().getIdString());

        } else {
            // TODO See if this can be injected.
            FacesContext context = FacesContext.getCurrentInstance();
            FacesMessage message = new FacesMessage(
                    "Cargo with tracking ID: " + trackingId + " not found.");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            context.addMessage(null, message);
            this.cargo = null;
        }
    }
 
Example 7
Source File: BookingBackingBean.java    From pragmatic-microservices-lab with MIT License 5 votes vote down vote up
public String register() {

        String trackingId = null;
        try {
            if (!originUnlocode.equals(destinationUnlocode)) {
                trackingId = bookingServiceFacade.bookNewCargo(
                        originUnlocode,
                        destinationUnlocode,
                        //new SimpleDateFormat(FORMAT).parse(arrivalDeadline));
                        //new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(arrivalDeadline)); // davidd
                        arrivalDeadline);

            } else {
                // TODO See if this can be injected.
                FacesContext context = FacesContext.getCurrentInstance();
                // UI now prevents from selecting same origin/destination
                FacesMessage message = new FacesMessage("Origin and destination cannot be the same.");
                message.setSeverity(FacesMessage.SEVERITY_ERROR);
                context.addMessage(null, message);
                return null;
            }
        } catch (Exception e) {
            throw new RuntimeException("Error parsing date", e); // todo, not parsing anymore
        }
        //return "show_original.xhtml?faces-redirect=true&trackingId=" + trackingId;
        return "/admin/dashboard.xhtml";
    }
 
Example 8
Source File: DashboardManagedBean.java    From journaldev with MIT License 5 votes vote down vote up
public void handleReorder(DashboardReorderEvent event) {
	FacesMessage message = new FacesMessage();
	message.setSeverity(FacesMessage.SEVERITY_INFO);
	message.setSummary("Reordered: " + event.getWidgetId());
	message.setDetail("Item index: " + event.getItemIndex()+ ", Column index: " + event.getColumnIndex() 
			+ ", Sender index: " + event.getSenderColumnIndex());

	addMessage(message);
}
 
Example 9
Source File: AnswerBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void validatePartialCredit(FacesContext context,  UIComponent toValidate,Object value){
	Integer pCredit = null;
	boolean isValid = true;
	if ("0.0".equals(value.toString())) {
		pCredit = 0;
	}
	else {
		try {
			pCredit = Integer.parseInt(value.toString());
		}
		catch (NumberFormatException e) {
			isValid = false;
		}
	}
	
	if(isValid && (pCredit==null || pCredit<0 || pCredit>99 )){
		isValid = false;
	}
	
	if (!isValid) {
		((UIInput)toValidate).setValid(false);
		FacesMessage message=new FacesMessage();
		message.setSeverity(FacesMessage.SEVERITY_ERROR);
		String summary=ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.AuthorMessages","partial_credit_limit_summary");
		String detail =ContextUtil.getLocalizedString("org.sakaiproject.tool.assessment.bundle.AuthorMessages","partial_credit_limit_detail"); 
		message.setSummary(summary) ;
		message.setDetail(detail);   
		context.addMessage(toValidate.getClientId(context), message);
	}
}
 
Example 10
Source File: MobileValidator.java    From journaldev with MIT License 5 votes vote down vote up
@Override
public void validate(FacesContext fc, UIComponent uic, Object obj)
		throws ValidatorException {

	String model = (String) obj;

	if (model.length() > 6) {
		FacesMessage msg = new FacesMessage(
				" Maximum Length of 6 is exceeded.Please enter values within range");
		msg.setSeverity(FacesMessage.SEVERITY_ERROR);

		throw new ValidatorException(msg);
	}

}
 
Example 11
Source File: BookingBackingBean.java    From pragmatic-microservices-lab with MIT License 5 votes vote down vote up
public String register() {

        String trackingId = null;
        try {
            if (!originUnlocode.equals(destinationUnlocode)) {
                trackingId = bookingServiceFacade.bookNewCargo(
                        originUnlocode,
                        destinationUnlocode,
                        //new SimpleDateFormat(FORMAT).parse(arrivalDeadline));
                        //new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(arrivalDeadline)); // davidd
                        arrivalDeadline);

            } else {
                // TODO See if this can be injected.
                FacesContext context = FacesContext.getCurrentInstance();
                // UI now prevents from selecting same origin/destination
                FacesMessage message = new FacesMessage("Origin and destination cannot be the same.");
                message.setSeverity(FacesMessage.SEVERITY_ERROR);
                context.addMessage(null, message);
                return null;
            }
        } catch (Exception e) {
            throw new RuntimeException("Error parsing date", e); // todo, not parsing anymore
        }
        //return "show_original.xhtml?faces-redirect=true&trackingId=" + trackingId;
        return "/admin/dashboard.xhtml";
    }
 
Example 12
Source File: EmailValidator.java    From java-course-ee with MIT License 5 votes vote down vote up
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {

    matcher = pattern.matcher(value.toString());
    if(isEmptyString(value.toString()) || !matcher.matches()){
        FacesMessage msg =new FacesMessage("E-mail validation failed.", "Invalid E-mail format.");
        msg.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(msg);
    }

}
 
Example 13
Source File: PackageValidator.java    From microprofile-starter with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(FacesContext facesContext, UIComponent uiComponent, Object value) throws ValidatorException {

    PackageNameValidator validator = retrieveInstance(PackageNameValidator.class);
    if (!validator.isValidPackageName(value.toString())) {
        FacesMessage msg =
                new FacesMessage(((HtmlInputText) uiComponent).getLabel() + " field validation failed.",
                        "Please provide a valid package name");
        msg.setSeverity(FacesMessage.SEVERITY_ERROR);

        throw new ValidatorException(msg);
    }
}
 
Example 14
Source File: LoginValidator.java    From sample.daytrader7 with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
 if (Log.doTrace()) {
  Log.trace("LoginValidator.validate","Validating submitted login name -- " + value.toString());
 }
 matcher = pattern.matcher(value.toString());
  
 if (!matcher.matches()) {
  FacesMessage msg = new FacesMessage("Username validation failed. Please provide username in this format: uid:#");
  msg.setSeverity(FacesMessage.SEVERITY_ERROR);
    
  throw new ValidatorException(msg);
 }
	}
 
Example 15
Source File: BookingBackingBean.java    From pragmatic-microservices-lab with MIT License 5 votes vote down vote up
public String register() {

        String trackingId = null;
        try {
            if (!originUnlocode.equals(destinationUnlocode)) {
                trackingId = bookingServiceFacade.bookNewCargo(
                        originUnlocode,
                        destinationUnlocode,
                        //new SimpleDateFormat(FORMAT).parse(arrivalDeadline));
                        //new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(arrivalDeadline)); // davidd
                        arrivalDeadline);

            } else {
                // TODO See if this can be injected.
                FacesContext context = FacesContext.getCurrentInstance();
                // UI now prevents from selecting same origin/destination
                FacesMessage message = new FacesMessage("Origin and destination cannot be the same.");
                message.setSeverity(FacesMessage.SEVERITY_ERROR);
                context.addMessage(null, message);
                return null;
            }
        } catch (Exception e) {
            throw new RuntimeException("Error parsing date", e); // todo, not parsing anymore
        }
        //return "show_original.xhtml?faces-redirect=true&trackingId=" + trackingId;
        return "/admin/dashboard.xhtml";
    }
 
Example 16
Source File: ELSampleBean.java    From tutorials with MIT License 5 votes vote down vote up
public void saveByELEvaluation() {
    firstName = (String) evaluateEL("#{firstName.value}", String.class);
    FacesContext ctx = FacesContext.getCurrentInstance();
    FacesMessage theMessage = new FacesMessage("Name component Evaluated: " + firstName);
    theMessage.setSeverity(FacesMessage.SEVERITY_INFO);
    ctx.addMessage(null, theMessage);

}
 
Example 17
Source File: SectionTitleValidator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public void validate(FacesContext context, UIComponent toValidate, Object value) throws ValidatorException {
    String str = (String) value;
    if (str.trim().length() < 1) {
        ((UIInput) toValidate).setValid(false);

        FacesMessage message = new FacesMessage();
        String messageText = JsfUtil.getLocalizedMessage("sectionTitle.validator.stringWithSpaceOnly");
        message.setDetail(messageText);
        message.setSummary(messageText);
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(message);
    }
}
 
Example 18
Source File: ChatTool.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void validatePositiveNumber(FacesContext context, UIComponent component, Object value){
  if (value != null)
  {
	
   if ((Integer) value < 0)
   {
     FacesMessage message = new FacesMessage(getMessageFromBundle("neg_num_error",null));
     message.setSeverity(FacesMessage.SEVERITY_WARN);
     throw new ValidatorException(message);
   }
	
  }
}
 
Example 19
Source File: SchedulerTool.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void validateTriggerExpression(FacesContext context,
    UIComponent component, Object value)
{
  if (value != null)
  {
    try
    {
      String expression = (String) value;

      // additional check
      // quartz does not check for more than 7 tokens in expression
      String[] arr = expression.split("\\s");
      if (arr.length > 7)
      {
        throw new RuntimeException(new ParseException("Expression has more than 7 tokens", 7));
      }

      TriggerBuilder.newTrigger()
              .withSchedule(CronScheduleBuilder.cronSchedule(expression))
              .build();

    }
    catch (RuntimeException e)
    {
      Throwable cause = e.getCause();
      String error = e.getMessage();
      if (cause != null)
      {
          error = cause.getMessage();
      }
      FacesMessage message = new FacesMessage(rb.getFormattedMessage("parse_exception", error));
      message.setSeverity(FacesMessage.SEVERITY_ERROR);
      throw new ValidatorException(message);
    }
  }
}
 
Example 20
Source File: MessageFactory.java    From journaldev with MIT License 4 votes vote down vote up
public static FacesMessage getMessage(final String messageId,
        final FacesMessage.Severity severity, final Object... params) {
    final FacesMessage facesMessage = getMessage(getLocale(), messageId, params);
    facesMessage.setSeverity(severity);
    return facesMessage;
}