You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Patrick Casey <pa...@adelphia.net> on 2005/09/26 23:05:16 UTC

Working with Validation Delegates in Code

	I've run into a situation where I have multiple levels of validation
going on during a form submit;

1) Form level validation (collected in an IValidationDelegate).
2) Metadata level validation (Collected in my own ErrorAggregator).
3) Database level validation (Collected in my own ErrorAggregator).


I'd like to build one global "MessageBox" component that I can put on every
form to display all three classes of error message together since the user
neither knows, nor cares, which level of the application complained that
"login cannot be blank".

Right now, I've got the MessageBox component up and running happily over my
ErrorAggregator, and at the step where I want to push the errors from the
Tapestry Validation Delegate into my ErrorAggregator (translating as
necessary). I'm sort of stumped though.

So far I've gotten:

IValidationDelegate delegate = (IValidationDelegate) getBeans()
				.getBean("delegate");
		if (delegate.getHasErrors()) {
			// what goes here?
		}

I can get the delegate (no problem), but I can't seem to crack the nut to
get at the error objects contained therein. Can anyone help me out here? All
I really want are the error strings; my error rendering will take care of
formatting and rendering them, but I need to know the text to render.

	Suggestions?

	--- Pat



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Working with Validation Delegates in Code

Posted by Dan Adams <da...@ifactory.com>.
I developed the same kind of component. Here's my code (nevermind the
'message' stuff):

<span jwcid="@If" condition="ognl:(delegate.hasErrors || message)">
<div class="errors" id="errors">

<ul>
<li jwcid="@Foreach" source="ognl:delegate.getErrorRenderers()"
value="ognl:error" element="li"><span jwcid="@Delegator"
delegate="ognl:error">error message here</span></li>
</ul>

</div>
</span>

You just call getErrorRenderers to get each of the IRender objects
(which just display strings by default).

On Mon, 2005-09-26 at 14:05 -0700, Patrick Casey wrote:
> 	I've run into a situation where I have multiple levels of validation
> going on during a form submit;
> 
> 1) Form level validation (collected in an IValidationDelegate).
> 2) Metadata level validation (Collected in my own ErrorAggregator).
> 3) Database level validation (Collected in my own ErrorAggregator).
> 
> 
> I'd like to build one global "MessageBox" component that I can put on every
> form to display all three classes of error message together since the user
> neither knows, nor cares, which level of the application complained that
> "login cannot be blank".
> 
> Right now, I've got the MessageBox component up and running happily over my
> ErrorAggregator, and at the step where I want to push the errors from the
> Tapestry Validation Delegate into my ErrorAggregator (translating as
> necessary). I'm sort of stumped though.
> 
> So far I've gotten:
> 
> IValidationDelegate delegate = (IValidationDelegate) getBeans()
> 				.getBean("delegate");
> 		if (delegate.getHasErrors()) {
> 			// what goes here?
> 		}
> 
> I can get the delegate (no problem), but I can't seem to crack the nut to
> get at the error objects contained therein. Can anyone help me out here? All
> I really want are the error strings; my error rendering will take care of
> formatting and rendering them, but I need to know the text to render.
> 
> 	Suggestions?
> 
> 	--- Pat
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
-- 
Dan Adams
Software Engineer
Interactive Factory


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Working with Validation Delegates in Code

Posted by "Filip S. Adamsen" <fi...@stubkjaer-adamsen.dk>.
Oops, that's something new - no @since in the source, hence I didn't 
notice... I believe what you're doing now is the only way in 3.0.3, but 
I might be wrong.

-Filip

Patrick Casey wrote:
> 	Sorry to be dense here, but I'm not seeing a getErrorRenderers()
> method in the IValidationDelegate interface. Is that something that went
> into tapestry 4.0? I'm still on 3.0.3.
> 
> 	I think I found a 3.0.3 way of doing it, but I'm not super happy
> about it.
> 
> 		IValidationDelegate delegate = (IValidationDelegate)
> getBeans()
> 				.getBean("delegate");
> 		if (delegate.getHasErrors()) {
> 			Visit v = (Visit) getPage().getVisit();
> 
> 			List l = delegate.getFieldTracking();
> 			for (int x=0; x< l.size(); x++) {
> 				Object o = l.get(x);
> 				FieldTracking f = (FieldTracking) o;
> 				if (f.getErrorRenderer() != null) {
> 	
> v.getMessageQueue().addError(f.getErrorRenderer().toString());
> 				}
> 
> 			}
> 		}

RE: Working with Validation Delegates in Code

Posted by Patrick Casey <pa...@adelphia.net>.
	Sorry to be dense here, but I'm not seeing a getErrorRenderers()
method in the IValidationDelegate interface. Is that something that went
into tapestry 4.0? I'm still on 3.0.3.

	I think I found a 3.0.3 way of doing it, but I'm not super happy
about it.

		IValidationDelegate delegate = (IValidationDelegate)
getBeans()
				.getBean("delegate");
		if (delegate.getHasErrors()) {
			Visit v = (Visit) getPage().getVisit();

			List l = delegate.getFieldTracking();
			for (int x=0; x< l.size(); x++) {
				Object o = l.get(x);
				FieldTracking f = (FieldTracking) o;
				if (f.getErrorRenderer() != null) {
	
v.getMessageQueue().addError(f.getErrorRenderer().toString());
				}

			}
		}

> -----Original Message-----
> From: Filip S. Adamsen [mailto:filip@stubkjaer-adamsen.dk]
> Sent: Monday, September 26, 2005 2:17 PM
> To: Tapestry users
> Subject: Re: Working with Validation Delegates in Code
> 
> Doh, sorry - I meant IRender#toString()... :$
> 
> -Filip
> 
> Filip S. Adamsen wrote:
> > Hmm, you could query IValidationDelegate#getErrorRenderers() and call
> > IRender#getString() on each object in the returned list to get the error
> > messages?
> >
> > -Filip
> >
> > Patrick Casey wrote:
> >  > All
> >
> >> I really want are the error strings; my error rendering will take care
> of
> >> formatting and rendering them, but I need to know the text to render.
> >>
> >>     Suggestions?
> >>
> >>     --- Pat



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Working with Validation Delegates in Code

Posted by "Filip S. Adamsen" <fi...@stubkjaer-adamsen.dk>.
Doh, sorry - I meant IRender#toString()... :$

-Filip

Filip S. Adamsen wrote:
> Hmm, you could query IValidationDelegate#getErrorRenderers() and call 
> IRender#getString() on each object in the returned list to get the error 
> messages?
> 
> -Filip
> 
> Patrick Casey wrote:
>  > All
> 
>> I really want are the error strings; my error rendering will take care of
>> formatting and rendering them, but I need to know the text to render.
>>
>>     Suggestions?
>>
>>     --- Pat

Re: Working with Validation Delegates in Code

Posted by "Filip S. Adamsen" <fi...@stubkjaer-adamsen.dk>.
Hmm, you could query IValidationDelegate#getErrorRenderers() and call 
IRender#getString() on each object in the returned list to get the error 
messages?

-Filip

Patrick Casey wrote:
 > All
> I really want are the error strings; my error rendering will take care of
> formatting and rendering them, but I need to know the text to render.
> 
> 	Suggestions?
> 
> 	--- Pat