Mercurial > hg > LGDataverses
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 9:5926d6419569 | 10:a50cf11e5178 |
|---|---|
| 1 /* | |
| 2 * To change this license header, choose License Headers in Project Properties. | |
| 3 * To change this template file, choose Tools | Templates | |
| 4 * and open the template in the editor. | |
| 5 */ | |
| 6 package edu.harvard.iq.dataverse; | |
| 7 | |
| 8 import javax.faces.application.FacesMessage; | |
| 9 import javax.faces.component.UIComponent; | |
| 10 import javax.faces.component.UIInput; | |
| 11 import javax.faces.context.FacesContext; | |
| 12 import javax.faces.validator.FacesValidator; | |
| 13 import javax.faces.validator.Validator; | |
| 14 import javax.faces.validator.ValidatorException; | |
| 15 | |
| 16 @FacesValidator(value = "linkValidator") | |
| 17 public class LinkValidator implements Validator { | |
| 18 | |
| 19 @Override | |
| 20 public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { | |
| 21 UIInput taglineInput = (UIInput) component.getAttributes().get("taglineInput"); | |
| 22 UIInput linkUrlInput = (UIInput) component.getAttributes().get("linkUrlInput"); | |
| 23 | |
| 24 String taglineStr = (String) taglineInput.getSubmittedValue(); | |
| 25 String urlStr = (String) linkUrlInput.getSubmittedValue(); | |
| 26 | |
| 27 FacesMessage msg = null; | |
| 28 if (taglineStr.isEmpty() && !urlStr.isEmpty()) { | |
| 29 msg = new FacesMessage("Please enter a tagline for the website to be hyperlinked with."); | |
| 30 msg.setSeverity(FacesMessage.SEVERITY_ERROR); | |
| 31 FacesContext.getCurrentInstance().addMessage(taglineInput.getClientId(), msg); | |
| 32 } | |
| 33 | |
| 34 if (msg != null) { | |
| 35 throw new ValidatorException(msg); | |
| 36 } | |
| 37 | |
| 38 } | |
| 39 | |
| 40 } |
