Announcement Announcement Module
Collapse
No announcement yet.
Jsf converter using webflow as cache Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jsf converter using webflow as cache

    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.

    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);
    	}
    Thank you very much!
    Last edited by leandroorilio; Mar 1st, 2012, 06:59 AM.
Working...
X