Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.66 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Strategy for mapping entity relationships and converting entities
  2. @Override
  3. public String getAsString(FacesContext context, UIComponent component, Object value) {
  4.     if (value == null) {
  5.         return null;
  6.     }
  7.  
  8.     Long id = ((BaseEntity) value).getId();
  9.     return String.valueOf(id);
  10. }
  11.  
  12. @Override
  13. @SuppressWarnings("unchecked")
  14. public Object getAsObject(FacesContext context, UIComponent component, String value) {
  15.     if (value == null) {
  16.         return null;
  17.     }
  18.  
  19.     Long id = Long.valueOf(value);
  20.     Class<BaseEntity> type = (Class<BaseEntity>) component.getValueExpression("value").getType(context.getELContext());
  21.     return genericDAO.find(id, type);
  22. }