Skip to content

Instantly share code, notes, and snippets.

@rbe
Created September 26, 2012 08:58
Show Gist options
  • Save rbe/3786899 to your computer and use it in GitHub Desktop.
Save rbe/3786899 to your computer and use it in GitHub Desktop.
Faces Converter for User entity, used for recipients
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