Created
September 26, 2012 08:58
-
-
Save rbe/3786899 to your computer and use it in GitHub Desktop.
Faces Converter for User entity, used for recipients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.faces.component.UIComponent; | |
import javax.faces.context.FacesContext; | |
import javax.faces.convert.Converter; | |
import javax.faces.convert.FacesConverter; | |
@FacesConverter("recipient") | |
public class RecipientConverter implements Converter { | |
@Override | |
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) { | |
User user = null; | |
if (null != s) { | |
user = new user(); | |
user.setUsername(s); | |
} | |
return user; | |
} | |
@Override | |
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) { | |
String r = ""; | |
if (o instanceof User) { | |
User user = (User) o; | |
r = user.getUsername(); | |
} else if (o instanceof String) { | |
r = (String) o; | |
} | |
return r; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment