On 14 Oct 2014, at 1:14 pm, George Christman <gchrist...@cardaddy.com> wrote:

> So I was able to get it working by using the following code inside of
> SiteIndex, but this does not seem very reusable.
> 
> @InjectComponent
>    private Layout layout;
> 
> void onShowLoginRegister() {
>        layout.onShowLoginRegister();
>    }
> 
> So is this the correct way to do this for this scenario?

Looks ok, but I think it's worth following this philosophy: A component should 
be responsible for itself and its children, that's all. The events that it 
bubbles up should be less like commands and more like "status reports".

In light of this it might be better to bubble up "authenticated", and it might 
be better for Layout to expose doRefreshUserName().

> My next question which I think is a little bit more complicating is
> how do I use my void onShowLoginRegister event handler to refresh
> multiple zones in different components and still keep the code
> reusable? Is that possible?

Reuse?

Let SiteIndex decide which components/zones to refresh based on the events that 
bubble up and their origin. Only SiteIndex should know what SiteIndex contains, 
so it's the right guy to make these decisions. It sounds like you're still 
trying to make components command their containers. If you let go of that idea 
then the rest will fall into place, elegantly delegated and decoupled.
 
> On Mon, Oct 13, 2014 at 8:27 PM, George Christman
> <gchrist...@cardaddy.com> wrote:
>> John I'm a little confused with step 2.
>>> 
>>> 1) componentA - trigger event
>>> onSuccessFromLogin() {
>>>    componentResources.triggerEvent("LoginComplete"...
>>> 
>>> 2) container of both A and B components - handover event
>>> onLoginComplete(Object[] ctxValues) {
>>>    componentB.onLoginComplete(ctxValues)
>> I don't understand this method, where does it belong? I thought the
>> idea was not to couple these so tightly together?
>>> ...
>>> }
>>> 
>>> 3) componentB - handle event
>>> onLoginComplete(Object[] ctxValues) {
>>>    ajaxResponseRenderer.addRender(zone);
>>> }
>> 
>> Also, can componentResources.triggerEvent("LoginComplete", null, null)
>> be called from any component and fire the event handler within the
>> layout component?
>> 
>> I have an example where I have layout, page, component and I'm trying
>> to trigger logginComplete from the component to the layout and can't
>> seem to get it to work.
>> 
>> 
>> looks kinda like this
>> 
>> @Events({Create.LOGINREGISTER})
>> public class Create {
>> 
>>    public static final String LOGINREGISTER = "showLoginRegister";
>> 
>> public void onValidateFromForm() {
>>        setVehicleData();
>> 
>>        if (form.isValid() && userProfile == null) {
>>            System.out.println("onValidate");
>>            componentResources.triggerEvent(LOGINREGISTER, null, null);
>>        }
>> 
>>    }
>> }
>> 
>> public class Layout {
>> 
>> void onShowLoginRegister() {
>>        function = Function.LOGIN;
>> 
>>        if (request.isXHR()) {
>>            ajaxResponseRenderer.addRender(loginRegisterModalZone);
>>        }
>> 
>>    }
>> }
>> 
>> SellIndex calls Layout component and also calls Create component. The
>> login exist in the layout and I'm trying to fire it from the Create
>> component.
>> 
>> <html t:type="layout">
>>    <t:create/>
>> </html>
>> 
>> 
>> 
>> 
>>> 
>>> 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
> 
> 
> 
> -- 
> George Christman
> www.CarDaddy.com
> P.O. Box 735
> Johnstown, New York
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to