Results 1 to 2 of 2

Thread: finders and jquery

Threaded View

  1. #1
    Join Date
    Jan 2011
    Location
    Santiago, Chile
    Posts
    9

    Default finders and jquery

    Hi again friends!
    I have a problem generating a finder... the problem (1 of them) is:
    is there any way to create a dynamic finder wich alows me to search even if the user inputs just 1 of the parameters?
    this is the code I manually created:


    Code:
    public static TypedQuery<Doc> searcher(String name,  Date minDate, Date maxDate, String description) {
    	    	int count=0;
    	    	String query="SELECT Doc FROM Doc AS doc WHERE ";
    	    	EntityManager em =Doc.entityManager();	        
    	        if (name != null && name.length() > 0){
    	        	if(count>0){
    	        		query+=" AND ";
    	        	}
    	        	query+="doc.name = :name";
    	        	count++;
    	        }
    	        if ((minDate != null)&&(maxDate!=null)){
    	        	if(count>0){
    	        		query+=" AND ";
    	        	}	        	
    	        	query+="doc.Date BETWEEN :minDate AND :maxDate";
    	        	count++;
    	        }
    	        if (description != null && description.length() > 0){
    	        	if(count>0){
    	        		query+=" AND ";
    	        	}
    	        	query+="doc.description = :description";
    	        	count++;
    	        }
    	        TypedQuery<Doc> q = em.createQuery(query, Doc.class);	        
    	        if((name!=null)&&(name.length()>0)){q.setParameter("name", name);}
    	        if(minDate!=null){q.setParameter("minDate", minDate);}
    	        if(maxDate!=null){q.setParameter("maxDate", maxDate);}
    	        if((description!=null)&&(description.length()>0)){q.setParameter("description", description);}	       
    	        return q;
    	    }
    the idea is the query could be done even if the user just inputs 1 parameter... I found this code a little complex, I don't know if roo (with finder add command) can make a finder with similar features...
    and my second problem is... how can I encapsulate a finder form within a popup? I'm using fancybox
    thanks
    Last edited by ycabello; Feb 17th, 2011 at 09:35 AM.

Posting Permissions

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