tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Viktor Szathmary" <phrak...@imapmail.org>
Subject helper bean lifecycle
Date Sun, 02 Feb 2003 00:04:01 GMT

regarding my issue with delegate helper bean lifecycle (that it's created
only once for the request, not N times in a Foreach loop) - here's the
workaround i came up with... first of all i had to expose the delegate
(make it a binding) on the component - it cannot be encapsulated anymore,
since the component doesnt know how many times it's repeated.

imagine you have three nested loops in a Page (forEachFoo, forEachBaz,
forEachBar) - and in the inner loop you have a component with a Form in
it... this is what you can do:

private Map delegates;

public void initialize() {
	this.delegates = new HashMap();

public IValidationDelegate getCurrentDelegate() {
	Foreach foo = (Foreach)this.getComponent("forEachFoo");
	Foreach bar = (Foreach)this.getComponent("forEachBar");
	Foreach baz = (Foreach)this.getComponent("forEachBaz");
	String index = foo.getIndex() + "/" + bar.getIndex() + "/" + baz.getIndex();

	IValidationDelegate delegate = (IValidationDelegate)this.delegates.get( index );
	if (delegate==null) {
		delegate = new ValidationDelegate();
		this.delegates.put(index, delegate);
	return delegate;

then bind currentDelegate as the delegate for the component...

however, this whole thing seems just plain ugly... and you have to
violate component encapsulation as well - the client (Page) needs to know
about what a component needs to do inside (that it uses a delegate)...
the whole point of Tapestry is component reuse, but at this point it
seems to fail...

so, is there a nicer way to do this whole thing?

best regards,

http://fastmail.fm - Access your email from home and the web

View raw message