[jboss-user] [JBoss Seam] - Validation on update

ama55 do-not-reply at jboss.com
Wed Dec 6 12:06:04 EST 2006


Dear all:
I am trying to validate the fields upon update.
in the update method i created a query statement that checks if the a value is unique. 
here is the update function
	@IfInvalid(outcome = Outcome.REDISPLAY)
  | 	public String update() {
  | 		String compName = instance.getName();
  | 		String compTel = instance.getTel();
  | 		String compFax = instance.getFax();
  | 		int compId = instance.getId();
  | 		
  | 		entityManager.refresh(instance);
  | 		
  | 		if (compName.equals(instance.getName())) {
  | 			instance.setTel(compTel);
  | 			instance.setFax(compFax);
  | 			entityManager.flush();
  | 			refreshFinder();
  | 			return null;
  | 		}
  | 		else {
  | 			Query query1 = entityManager.createQuery("select comp from Companies comp where comp.name=:compName");
  | 			query1.setParameter("compName", compName);
  | 			
  | 			if (query1.getResultList() != null) {
  | 				FacesContext.getCurrentInstance().addMessage(
  | 						null,
  | 						new FacesMessage(messages.get("Companies_name") + " "
  | 								+ messages.get("AlreadyExists")));			
  | 				return null;				
  | 			}			
  | 		}
  | 		instance=(Companies)entityManager.find(Companies.class, compId); 
  | 		instance.setName(compName);
  | 		instance.setTel(compTel);
  | 		instance.setFax(compFax);
  | 		entityManager.flush();
  | 		refreshFinder();
  | 		return null;
  | 	}

If the user tries to enter a company name that already exists in the database then an error is reported. (works fine)
but if the user tries to enter a company name that doesnot exist in the database then an error is also reported. the problem is that in this case the query statement returns a list but it is not supposed to do so.

any one knows how to solve that.

Best regards
ama55

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3991713#3991713

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3991713



More information about the jboss-user mailing list