Hi,
Have a look for a thread I started called "component events bubbling down?".
There's a link and some discussion that should help you.
On the whole it is generally advisable to avoid tight coupling between
component type classes because it reduced reusability. It is specifically
desirable for child components not to be tightly coupled to their parent
classes. At the very least, if you do couple, couple loosely using the observer
design pattern or similar.
The approach I take is to trigger a component event and then a high level
container can pick this up and pass it back down to sibling components.
eg:
1) componentA - trigger event
onSuccessFromLogin() {
componentResources.triggerEvent("LoginComplete"...
2) container of both A and B components - handover event
onLoginComplete(Object[] ctxValues) {
componentB.onLoginComplete(ctxValues)
...
}
3) componentB - handle event
onLoginComplete(Object[] ctxValues) {
ajaxResponseRenderer.addRender(zone);
}
This is a little clumsy, looks boilerplate and should be done in the background
with a publisher-subscriber annotation provided by the framework IMO. But it is
completely decoupled with respect to the components. :)
regards,
John
----- Original Message -----
From: George Christman
To: Tapestry users
Sent: Monday, October 13, 2014 6:38 AM
Subject: How do I render zone from component A in component B
I have a modal login box. When a user logs in through the login box, I
would like to reload a zone in the nav bar containing the user name which
is contained within the layout component. I've tried to use
@InjectComponent and call a method from within the layout component, but I
get
*Unable to attach page sell/Index: Unable to inject component into field
layout of class com.cardaddy.auto.components.LoginRegister: Component
sell/Index:layout.loginregister does not contain embedded component
'layout'.*
The code looks something like
//html is the layout component
<html>
<t:zone t:id="loginNavZone>Hi ${name}</t:zone>
<t:modaldialog>
<loginregister/>
</t:modaldialog>
</html>
public class LoginRegister {
@InjectComponent
private Layout layout;
public void onValidateFromLoginForm() {
layout.getLoginNavZone();
}
}
public class Layout {
public void getLoginNavZone() {
ajaxResponseRenderer.addRender("loginNavZone", loginNavZone);
}
}
I know how to access a page using @PageInject from a component, but I can
not seem to access a component from within a component unless I declare the
component within the tml. Anybody know how to accomplish this?
--
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York
---
This email is free from viruses and malware because avast! Antivirus protection
is active.
http://www.avast.com