0

Form validation and WrongValuesException

asked 2011-03-28 07:54:39 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

updated 2011-03-28 07:55:06 +0800

I am not sure if this is related to ZK or my own deficiency in Exception handling...
While trying to validate a form (see previous related post http://www.zkoss.org/forum/listComment/15648*) I am doing something like:

	public void onClick$submitContract(Event event) {

		try {
			this.validateForm(event.getTarget().getSpaceOwner());
                        ...
		} catch (Exception e) {
			logger.error("Failed while submitting contract (" + e.getMessage() + ")");
			e.printStackTrace();
		}

	}



	private void validateForm(IdSpace idSpace){

		ArrayList<WrongValueException> wve = new ArrayList<WrongValueException>();

		wve.add(this.getEmptySimpleFieldException(idSpace, "cost_centre_id", "error message"));
                wve.add (...N times for N fields...);
		



	private WrongValueException getEmptySimpleFieldException (IdSpace idSpace, String field, String message) {
		try {
			Component c = idSpace.getFellow(field);
			if (c.getAttribute("value")=="" || c.getAttribute("value") == null)
				return new WrongValueException(c, message);			
		} catch (Exception e) {
			logger.error("Failed while validating simple field '"+field+"' in contract form ("+e.getMessage()+")");					
		}

		return null;
	}

If I intercept the Exception as in the first method, then no feedback is prompted on the UI.
If I do something like this instead (I did it by chance in another class...)

	public void onClick$submitContract(Event event) {
		try {
			this.validateForm(event.getTarget().getSpaceOwner());			
			Messagebox.show("**CONTRACT ADDED SUCCESSFULLY");
		} catch (InterruptedException e) {
			logger.error("Failed while submitting contract (" + e.getMessage() + ")");
			e.printStackTrace();
		}
	}

everything works fine...
Should I then simply let it go and "bubble up"?
I apologize if this is not ZK but pure Java Exceptions handling... bad habit of intercepting generic Exception maybe...
Thanks
S

*See also
http://www.zkoss.org/forum/listComment/11916
http://www.zkoss.org/forum/listComment/11525

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2011-03-28 08:18:10 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

Yes... it must be simply Exception handling... this way it works fine (look at throws clause and login in catch block, letting the WrongValuesException bubble up)

	public void onClick$submitContract(Event event) throws WrongValuesException {

		try {
			this.validateForm(event.getTarget().getSpaceOwner());			
			...
		} catch (Exception e) {
			if (e.getClass().equals(WrongValuesException.class))
				throw (WrongValuesException) e;
			logger.error("Failed while submitting contract (" + e.getMessage() + ")");
			e.printStackTrace();
		}

	}

Sorry to those who wasted 2 minutes in reading the first post (+1 reading this one and my apologizes ;).
S

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-03-28 07:54:39 +0800

Seen: 386 times

Last updated: Mar 28 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More