Results 1 to 1 of 1

Thread: Jsf converter using webflow as cache

Threaded View

  1. #1

    Lightbulb 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 at 05:59 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •