view src/main/java/edu/harvard/iq/dataverse/LinkValidator.java @ 13:d3374217e19e

url config for LGMap
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Wed, 30 Sep 2015 13:55:57 +0200
parents a50cf11e5178
children
line wrap: on
line source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.harvard.iq.dataverse;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator(value = "linkValidator")
public class LinkValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        UIInput taglineInput = (UIInput) component.getAttributes().get("taglineInput");
        UIInput linkUrlInput = (UIInput) component.getAttributes().get("linkUrlInput");

        String taglineStr = (String) taglineInput.getSubmittedValue();
        String urlStr = (String) linkUrlInput.getSubmittedValue();

        FacesMessage msg = null;
        if (taglineStr.isEmpty() && !urlStr.isEmpty()) {
            msg = new FacesMessage("Please enter a tagline for the website to be hyperlinked with.");
            msg.setSeverity(FacesMessage.SEVERITY_ERROR);
            FacesContext.getCurrentInstance().addMessage(taglineInput.getClientId(), msg);
        }

        if (msg != null) {
            throw new ValidatorException(msg);
        }

    }

}