Hi folks,
I've implemented an jsf conveter using webflow's ViewScope as cache in order to improve throughput, reducing callings to database. I would like to know if I would have some problems with this implementation and if this is a good solution to create a jsf conveter to bussiness entities.
Thank you very much!Code:@Override public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) { if (submittedValue.trim().equals("")) { return null; } else { return (Product) retrieve(submittedValue); } } @Override public String getAsString(FacesContext facesContext, UIComponent component, Object value) { if (value == null || value.equals("")) { return ""; } else { String id = "product_" + new Random().nextInt() + "_" + ((Product) value).getId(); add((Product) value, id); return id; } } private Product retrieve(String id) { MutableAttributeMap viewScope = RequestContextHolder.getRequestContext().getViewScope(); return (Product) viewScope.get(id); } private void add(Product product, String id) { MutableAttributeMap viewScope = RequestContextHolder.getRequestContext().getViewScope(); viewScope.put(id, product); }


Reply With Quote
