diff src/main/java/edu/harvard/iq/dataverse/LinkValidator.java @ 10:a50cf11e5178

Rewrite LGDataverse completely upgrading to dataverse4.0
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 08 Sep 2015 17:00:21 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/edu/harvard/iq/dataverse/LinkValidator.java	Tue Sep 08 17:00:21 2015 +0200
@@ -0,0 +1,40 @@
+/*
+ * 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);
+        }
+
+    }
+
+}