Passing parent layout's object to nested page

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing parent layout's object to nested page

g kuczera
Hi Guys,
I have a custom layout named LayoutM (java class and tml). It is used by my
page - Activities - like that:

<t:layoutM title="${message:site.title} - ${message:page.title}"
           bodyClass="dashboard"
           xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
           xmlns:p="tapestry:parameter">
<!--a lot of stuff -->
</t:layoutM>

And it implements some kind of interface (class LayoutM implements
CustomInterface).
Is there a way to pass LayoutM java class object,+
 to Activities page? Activities page contains the field:
  @Parameter(required=false)
  private CustomInterface fieldName;

I saw
http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/T5-passing-values-between-layout-component-and-page-td2412095.html

but this works in the opposite way.

Is something like that correct (if I put it below "a lot of stuff" line)?

  <p:fieldName value=${this}></p:fieldName>

What I can see right now is the "this" being an instance of Activities
class. How can I get the parent layout's object?
Reply | Threaded
Open this post in threaded view
|

Re: Passing parent layout's object to nested page

nquirynen
Hey,

I'm not sure I totally understand your question, but if you just want to
access your components properties in your page I think you can do the
following (not tested):

Inject your layout component in your page like following:

@InjectComponent
private LayoutM layoutM;

public Object getSomeProperty() {
     return layoutM.getSomeProperty();
}

${someProperty}

Or with the @Property annotation you can access its properties in your
page as following:

@Property
@InjectComponent
private LayoutM layoutM;

${layoutM.someProperty}


Nathan

On 22/10/15 10:48, g kuczera wrote:

> Hi Guys,
> I have a custom layout named LayoutM (java class and tml). It is used by my
> page - Activities - like that:
>
> <t:layoutM title="${message:site.title} - ${message:page.title}"
>             bodyClass="dashboard"
>             xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
>             xmlns:p="tapestry:parameter">
> <!--a lot of stuff -->
> </t:layoutM>
>
> And it implements some kind of interface (class LayoutM implements
> CustomInterface).
> Is there a way to pass LayoutM java class object,+
>   to Activities page? Activities page contains the field:
>    @Parameter(required=false)
>    private CustomInterface fieldName;
>
> I saw
> http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/T5-passing-values-between-layout-component-and-page-td2412095.html
>
> but this works in the opposite way.
>
> Is something like that correct (if I put it below "a lot of stuff" line)?
>
>    <p:fieldName value=${this}></p:fieldName>
>
> What I can see right now is the "this" being an instance of Activities
> class. How can I get the parent layout's object?
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing parent layout's object to nested page

g kuczera
Hi Nathan,
To be honest, I just want to access the whole LayoutM object in the class,
that uses it. Right now I am able to access Activities' fields from within


<t:layoutM title="${message:site.title} - ${message:page.title}"
           bodyClass="dashboard"
           xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
           xmlns:p="tapestry:parameter">
<!--here I am accessing the Activities fields and now I want to take/pass
the whole LayoutM's instance object, pass it, to the actually rendered
page, which is Activities -->
<t:block id="successBlock"></t:block>
</t:layoutM>

successBlock is the field from Activities java class. I will try your
advice right away. But I already have a question about


@InjectComponent
private LayoutM layoutM;

Does it mean, that the layoutM, which is being used by Activities page
right now, will be just inflated/injected to the layoutM field? No new
object will be created, because it already, exists. Sorry for questioning
for basics, but I am still learning these new (for me) concepts.


2015-10-22 11:13 GMT+02:00 Nathan Quirynen <[hidden email]>:

> Hey,
>
> I'm not sure I totally understand your question, but if you just want to
> access your components properties in your page I think you can do the
> following (not tested):
>
> Inject your layout component in your page like following:
>
> @InjectComponent
> private LayoutM layoutM;
>
> public Object getSomeProperty() {
>     return layoutM.getSomeProperty();
> }
>
> ${someProperty}
>
> Or with the @Property annotation you can access its properties in your
> page as following:
>
> @Property
> @InjectComponent
> private LayoutM layoutM;
>
> ${layoutM.someProperty}
>
>
> Nathan
>
>
> On 22/10/15 10:48, g kuczera wrote:
>
>> Hi Guys,
>> I have a custom layout named LayoutM (java class and tml). It is used by
>> my
>> page - Activities - like that:
>>
>> <t:layoutM title="${message:site.title} - ${message:page.title}"
>>             bodyClass="dashboard"
>>             xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
>>             xmlns:p="tapestry:parameter">
>> <!--a lot of stuff -->
>> </t:layoutM>
>>
>> And it implements some kind of interface (class LayoutM implements
>> CustomInterface).
>> Is there a way to pass LayoutM java class object,+
>>   to Activities page? Activities page contains the field:
>>    @Parameter(required=false)
>>    private CustomInterface fieldName;
>>
>> I saw
>>
>> http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/T5-passing-values-between-layout-component-and-page-td2412095.html
>>
>> but this works in the opposite way.
>>
>> Is something like that correct (if I put it below "a lot of stuff" line)?
>>
>>    <p:fieldName value=${this}></p:fieldName>
>>
>> What I can see right now is the "this" being an instance of Activities
>> class. How can I get the parent layout's object?
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Passing parent layout's object to nested page

nquirynen
Yes it will inject the component defined in your Activities .tml file.
You have to use the t:id value as your property name though. But if you
don't define a t:id on your component I think the first will have a t:id
value the same as the components name, which in your case is layoutM.

But to be sure you can add the t:id:

<t:layoutM t:id="myLayoutComponent" ... />

@InjectComponent
private LayoutM myLayoutComponent;


Here's some more info on injection in Tapestry:

https://tapestry.apache.org/injection-faq.html



On 22/10/15 12:28, g kuczera wrote:

> Hi Nathan,
> To be honest, I just want to access the whole LayoutM object in the class,
> that uses it. Right now I am able to access Activities' fields from within
>
>
> <t:layoutM title="${message:site.title} - ${message:page.title}"
>             bodyClass="dashboard"
>             xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
>             xmlns:p="tapestry:parameter">
> <!--here I am accessing the Activities fields and now I want to take/pass
> the whole LayoutM's instance object, pass it, to the actually rendered
> page, which is Activities -->
> <t:block id="successBlock"></t:block>
> </t:layoutM>
>
> successBlock is the field from Activities java class. I will try your
> advice right away. But I already have a question about
>
>
> @InjectComponent
> private LayoutM layoutM;
>
> Does it mean, that the layoutM, which is being used by Activities page
> right now, will be just inflated/injected to the layoutM field? No new
> object will be created, because it already, exists. Sorry for questioning
> for basics, but I am still learning these new (for me) concepts.
>
>
> 2015-10-22 11:13 GMT+02:00 Nathan Quirynen <[hidden email]>:
>
>> Hey,
>>
>> I'm not sure I totally understand your question, but if you just want to
>> access your components properties in your page I think you can do the
>> following (not tested):
>>
>> Inject your layout component in your page like following:
>>
>> @InjectComponent
>> private LayoutM layoutM;
>>
>> public Object getSomeProperty() {
>>      return layoutM.getSomeProperty();
>> }
>>
>> ${someProperty}
>>
>> Or with the @Property annotation you can access its properties in your
>> page as following:
>>
>> @Property
>> @InjectComponent
>> private LayoutM layoutM;
>>
>> ${layoutM.someProperty}
>>
>>
>> Nathan
>>
>>
>> On 22/10/15 10:48, g kuczera wrote:
>>
>>> Hi Guys,
>>> I have a custom layout named LayoutM (java class and tml). It is used by
>>> my
>>> page - Activities - like that:
>>>
>>> <t:layoutM title="${message:site.title} - ${message:page.title}"
>>>              bodyClass="dashboard"
>>>              xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
>>>              xmlns:p="tapestry:parameter">
>>> <!--a lot of stuff -->
>>> </t:layoutM>
>>>
>>> And it implements some kind of interface (class LayoutM implements
>>> CustomInterface).
>>> Is there a way to pass LayoutM java class object,+
>>>    to Activities page? Activities page contains the field:
>>>     @Parameter(required=false)
>>>     private CustomInterface fieldName;
>>>
>>> I saw
>>>
>>> http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/T5-passing-values-between-layout-component-and-page-td2412095.html
>>>
>>> but this works in the opposite way.
>>>
>>> Is something like that correct (if I put it below "a lot of stuff" line)?
>>>
>>>     <p:fieldName value=${this}></p:fieldName>
>>>
>>> What I can see right now is the "this" being an instance of Activities
>>> class. How can I get the parent layout's object?
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing parent layout's object to nested page

Thiago H de Paula Figueiredo
In reply to this post by g kuczera
On Thu, 22 Oct 2015 06:48:34 -0200, g kuczera <[hidden email]> wrote:

> Hi Guys,

Hi!

> I have a custom layout named LayoutM (java class and tml). It is used by  
> my
> page - Activities - like that:
>
> <t:layoutM title="${message:site.title} - ${message:page.title}"
>            bodyClass="dashboard"
>            xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
>            xmlns:p="tapestry:parameter">
> <!--a lot of stuff -->
> </t:layoutM>
>
> And it implements some kind of interface (class LayoutM implements
> CustomInterface).
> Is there a way to pass LayoutM java class object,+
>  to Activities page?

Yes. The recommended way of passing information (objects) around is  
through parameters. When this isn't possible, such as in your case, you  
can use the Environment service. Examples in
http://tapestry.apache.org/environmental-services.html
https://tawus.wordpress.com/2011/04/25/tapestry-magic-6-environment/

> Is something like that correct (if I put it below "a lot of stuff" line)?
>
>   <p:fieldName value=${this}></p:fieldName>

No, this isn't correct in two different ways: there's no way to reference  
this in the prop binding (the default one) and, in addition, you shouldn't  
use ${} expansions in parameters. It's always either useless or a bug.

> What I can see right now is the "this" being an instance of Activities
> class. How can I get the parent layout's object?

@InjectContainer
private Object parentObject; // actually, the field can be of any type you  
want.

But you should try to avoid this, because it couples too much the  
component and its parent. Use the Environment instead.

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing parent layout's object to nested page

g kuczera
For now I tried the last approach, (InjectContainer), but it throws
Caused by: java.lang.NullPointerException
    at
org.apache.tapestry5.internal.transform.InjectContainerWorker$1$1.get(InjectContainerWorker.java:80)

It looks like it's not the proper way in my case. Trying other ways.
PS: Just wandering, if the container worker gets null, then it probably
means, that there is no container at all (for my current page, in which I
put the annotation).


2015-10-22 15:40 GMT+02:00 Thiago H de Paula Figueiredo <[hidden email]>
:

> On Thu, 22 Oct 2015 06:48:34 -0200, g kuczera <[hidden email]> wrote:
>
> Hi Guys,
>>
>
> Hi!
>
> I have a custom layout named LayoutM (java class and tml). It is used by my
>> page - Activities - like that:
>>
>> <t:layoutM title="${message:site.title} - ${message:page.title}"
>>            bodyClass="dashboard"
>>            xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
>>            xmlns:p="tapestry:parameter">
>> <!--a lot of stuff -->
>> </t:layoutM>
>>
>> And it implements some kind of interface (class LayoutM implements
>> CustomInterface).
>> Is there a way to pass LayoutM java class object,+
>>  to Activities page?
>>
>
> Yes. The recommended way of passing information (objects) around is
> through parameters. When this isn't possible, such as in your case, you can
> use the Environment service. Examples in
> http://tapestry.apache.org/environmental-services.html
> https://tawus.wordpress.com/2011/04/25/tapestry-magic-6-environment/
>
> Is something like that correct (if I put it below "a lot of stuff" line)?
>>
>>   <p:fieldName value=${this}></p:fieldName>
>>
>
> No, this isn't correct in two different ways: there's no way to reference
> this in the prop binding (the default one) and, in addition, you shouldn't
> use ${} expansions in parameters. It's always either useless or a bug.
>
> What I can see right now is the "this" being an instance of Activities
>> class. How can I get the parent layout's object?
>>
>
> @InjectContainer
> private Object parentObject; // actually, the field can be of any type you
> want.
>
> But you should try to avoid this, because it couples too much the
> component and its parent. Use the Environment instead.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Passing parent layout's object to nested page

Thiago H de Paula Figueiredo
On Fri, 23 Oct 2015 12:28:09 -0200, g kuczera <[hidden email]> wrote:

> For now I tried the last approach, (InjectContainer), but it throws
> Caused by: java.lang.NullPointerException
>     at
> org.apache.tapestry5.internal.transform.InjectContainerWorker$1$1.get(InjectContainerWorker.java:80)
> It looks like it's not the proper way in my case. Trying other ways.
> PS: Just wandering, if the container worker gets null, then it probably
> means, that there is no container at all (for my current page, in which I
> put the annotation).

You got it right. :) This will only work on components, not in pages,  
because pages don't have a container (parent). It would work from the  
Layout component to access the page on which it's used, for example.

Have you tried the Environment?

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing parent layout's object to nested page

g kuczera
For now I am using this strategy:
<t:layoutM t:id="myLayoutComponent" ... />

@InjectComponent
private LayoutM myLayoutComponent;

and it works well. Tomorrow I will be probably redesigning the app a little
bit, so I will give you my feedback about the Environment in the next few
days.

2015-10-23 18:23 GMT+02:00 Thiago H de Paula Figueiredo <[hidden email]>
:

> On Fri, 23 Oct 2015 12:28:09 -0200, g kuczera <[hidden email]> wrote:
>
> For now I tried the last approach, (InjectContainer), but it throws
>> Caused by: java.lang.NullPointerException
>>     at
>>
>> org.apache.tapestry5.internal.transform.InjectContainerWorker$1$1.get(InjectContainerWorker.java:80)
>> It looks like it's not the proper way in my case. Trying other ways.
>> PS: Just wandering, if the container worker gets null, then it probably
>> means, that there is no container at all (for my current page, in which I
>> put the annotation).
>>
>
> You got it right. :) This will only work on components, not in pages,
> because pages don't have a container (parent). It would work from the
> Layout component to access the page on which it's used, for example.
>
> Have you tried the Environment?
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>