comparison src/main/java/edu/harvard/iq/dataverse/ControlledVocabularyValueConverter.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.ejb.EJB;
9
10 import javax.faces.component.UIComponent;
11 import javax.faces.context.FacesContext;
12 import javax.faces.convert.Converter;
13 import javax.faces.convert.FacesConverter;
14
15 /**
16 *
17 * @author xyang
18 */
19 @FacesConverter("controlledVocabularyValueConverter")
20 public class ControlledVocabularyValueConverter implements Converter {
21
22 @EJB
23 DatasetFieldServiceBean datasetFieldService;
24
25 public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) {
26 if (submittedValue == null || submittedValue.equals("")) {
27 return "";
28 } else {
29 ControlledVocabularyValue cvv = datasetFieldService.findControlledVocabularyValue(new Long(submittedValue));
30 return cvv;
31 }
32 }
33
34 public String getAsString(FacesContext facesContext, UIComponent component, Object value) {
35 if (value == null || value.equals("")) {
36 return "";
37 } else {
38 return ((ControlledVocabularyValue) value).getId().toString();
39 }
40 }
41 }