You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Rizwan <ri...@gmail.com> on 2011/06/20 12:49:01 UTC

Using environment to access object in component from calling page

Hi I am trying to access a environment variable in a page.  The variable is
pushed onto the environment from the enclosed component.

The code for the component is something like the following

public class PageComponent {

	@Inject
	private Environment environment;

	@BeginRender
	Object pushObject() {
	    try {

			Display display = new Display();

			environment.push(Display.class, display);
	}
	
	@AfterRender
	void popObject () {
		environment.pop(Display.class);
	}
}


I want to now access my display object from the calling page but getting
errors that the object is not in the environment.

Calling page code is 

public class Page {

	@Environmental
	private Display display;


}

I have tried accessing this variable in BeginRender but does not work.  It
seems like the AfterRender on the component is being called before the page.


Could someone advise on a better way of doing this?

Thanks

Rizwan








--
View this message in context: http://tapestry.1045711.n5.nabble.com/Using-environment-to-access-object-in-component-from-calling-page-tp4505889p4505889.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Using environment to access object in component from calling page

Posted by Rizwan <ri...@gmail.com>.
Thanks Taha,

Could you provide me with a short example on how to do it the parameter way
as well.  Not sure I fully understand this method you described?

 Many thanks


Rizwan

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Using-environment-to-access-object-in-component-from-calling-page-tp4505889p4507177.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Using environment to access object in component from calling page

Posted by Taha Tapestry <ta...@gmail.com>.
Sorry @InjectCompoment not @inject

Regards
Taha 

On Jun 20, 2011, at 8:32 PM, Taha Tapestry <ta...@gmail.com> wrote:

> There are two ways of doing this
> One way is to use parameters. Create a parameter display in the component which will be readonly for the page and to which the component assigns a value like the index parameter of the loop
> 
> Second is to create an interface Displayable having a method getDisplay() and have the component implement that interface. In the page you can later use
> 
> @inject
> private MyComponent component;
> 
> public Display getDisplay(){
>   return ((Displayable)component).getDisplay();
> }
> 
> Regards
> Taha 
> 
> On Jun 20, 2011, at 8:10 PM, Rizwan <ri...@gmail.com> wrote:
> 
>> I have to push the object in the component as the information I need passed
>> back to the page is only in the component not the page.
>> 
>> From reading the tapestry API it seems that it is more cleaner to push and
>> pop the objects in the same component rather than popping and pushing in
>> different components?
>> 
>> Are there any alternatives or good ways of doing this.  The only way I can
>> think off is injecting the component into the page e.g
>> 
>> InjectComponent
>> private Component
>> 
>> public getDisplay () {
>> component.getDisplay();
>> 
>> }
>> 
>> Thanks
>> 
>> Rizwan
>> 
>> 
>> --
>> View this message in context: http://tapestry.1045711.n5.nabble.com/Using-environment-to-access-object-in-component-from-calling-page-tp4505889p4506608.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 

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


Re: Using environment to access object in component from calling page

Posted by Taha Tapestry <ta...@gmail.com>.
There are two ways of doing this
One way is to use parameters. Create a parameter display in the component which will be readonly for the page and to which the component assigns a value like the index parameter of the loop

Second is to create an interface Displayable having a method getDisplay() and have the component implement that interface. In the page you can later use

@inject
private MyComponent component;

public Display getDisplay(){
   return ((Displayable)component).getDisplay();
}

Regards
Taha 

On Jun 20, 2011, at 8:10 PM, Rizwan <ri...@gmail.com> wrote:

> I have to push the object in the component as the information I need passed
> back to the page is only in the component not the page.
> 
> From reading the tapestry API it seems that it is more cleaner to push and
> pop the objects in the same component rather than popping and pushing in
> different components?
> 
> Are there any alternatives or good ways of doing this.  The only way I can
> think off is injecting the component into the page e.g
> 
> InjectComponent
> private Component
> 
> public getDisplay () {
> component.getDisplay();
> 
> }
> 
> Thanks
> 
> Rizwan
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Using-environment-to-access-object-in-component-from-calling-page-tp4505889p4506608.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 

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


Re: Using environment to access object in component from calling page

Posted by Rizwan <ri...@gmail.com>.
I have to push the object in the component as the information I need passed
back to the page is only in the component not the page.

>From reading the tapestry API it seems that it is more cleaner to push and
pop the objects in the same component rather than popping and pushing in
different components?

Are there any alternatives or good ways of doing this.  The only way I can
think off is injecting the component into the page e.g

InjectComponent
private Component

public getDisplay () {
component.getDisplay();

}

Thanks

Rizwan


--
View this message in context: http://tapestry.1045711.n5.nabble.com/Using-environment-to-access-object-in-component-from-calling-page-tp4505889p4506608.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Using environment to access object in component from calling page

Posted by Taha Tapestry <ta...@gmail.com>.
I agree that information can be passed both ways but the object is pushed on to the environment by the parent/enclosing component

Regards
Taha 

On Jun 20, 2011, at 7:16 PM, "Thiago H. de Paula Figueiredo" <th...@gmail.com> wrote:

> On Mon, 20 Jun 2011 09:49:34 -0300, Taha Hafeez <ta...@gmail.com> wrote:
> 
>> Hi Rizwan,
> 
> Hi, guys!
> 
>> Environment is used when a component wants to pass an object to the
>> child/embedded component not other way around because of the reasons already mentioned by Thiago. If you describe the use case may be we can suggest you a better way.
> 
> I wouldn't that Environment is purely top-down. Of course, most of the time it is. Sometimes information goes both ways. The Form component adds a FormSupport object to the Environment and the form field components add validation, event triggering, etc commands for Form to execute while handling a form submission.
> 
> -- 
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br

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


Re: Using environment to access object in component from calling page

Posted by Josh Canfield <jo...@gmail.com>.
> I wouldn't that Environment is purely top-down. Of course, most of the time
> it is. Sometimes information goes both ways. The Form component adds a
> FormSupport object to the Environment and the form field components add
> validation, event triggering, etc commands for Form to execute while
> handling a form submission.

Just for clarity:

While the information goes both ways, the form component remains in
charge of the lifecycle. During rendering FormSupport is pushed in the
Form component's beginRender and popped in it's cleanupRender, and in
an action (form submit) FormSupport is pushed and popped from within
the onAction event handler.

The page or component containing the form has access to the
FormSupport only when the form or one of its sub-components trigger an
event between the time that the object was pushed and popped.

Josh

On Mon, Jun 20, 2011 at 6:46 AM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> On Mon, 20 Jun 2011 09:49:34 -0300, Taha Hafeez <ta...@gmail.com>
> wrote:
>
>> Hi Rizwan,
>
> Hi, guys!
>
>> Environment is used when a component wants to pass an object to the
>> child/embedded component not other way around because of the reasons
>> already mentioned by Thiago. If you describe the use case may be we can
>> suggest you a better way.
>
> I wouldn't that Environment is purely top-down. Of course, most of the time
> it is. Sometimes information goes both ways. The Form component adds a
> FormSupport object to the Environment and the form field components add
> validation, event triggering, etc commands for Form to execute while
> handling a form submission.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and
> instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: Using environment to access object in component from calling page

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 20 Jun 2011 09:49:34 -0300, Taha Hafeez <ta...@gmail.com>  
wrote:

> Hi Rizwan,

Hi, guys!

> Environment is used when a component wants to pass an object to the
> child/embedded component not other way around because of the reasons  
> already mentioned by Thiago. If you describe the use case may be we can  
> suggest you a better way.

I wouldn't that Environment is purely top-down. Of course, most of the  
time it is. Sometimes information goes both ways. The Form component adds  
a FormSupport object to the Environment and the form field components add  
validation, event triggering, etc commands for Form to execute while  
handling a form submission.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Using environment to access object in component from calling page

Posted by Taha Hafeez <ta...@gmail.com>.
Hi Rizwan,

Environment is used when a component wants to pass an object to the
child/embedded component not other way around because of the reasons already
mentioned by Thiago. If you describe the use case may be we can suggest you
a better way.

regards
Taha

On Mon, Jun 20, 2011 at 5:17 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Mon, 20 Jun 2011 07:49:01 -0300, Rizwan <ri...@gmail.com> wrote:
>
>  Hi
>>
>
> Hi!
>
>  I am trying to access a environment variable in a page.  The variable is
>> pushed onto the environment from the enclosed component.
>> public class PageComponent {
>>
>>        @Inject
>>        private Environment environment;
>>
>>        @BeginRender
>>        Object pushObject() {
>>            try {
>>
>>                        Display display = new Display();
>>
>>                        environment.push(Display.**class, display);
>>        }
>>
>>        @AfterRender
>>        void popObject () {
>>                environment.pop(Display.class)**;
>>        }
>> }
>> I have tried accessing this variable in BeginRender but does not work.  It
>> seems like the AfterRender on the component is being called before the page.
>>
>
> You're describing absolutely correct and expected behavior: your component
> is popping (removing) the Display object from the Environment after is
> rendered, but the page is still rendering, so when the @AfterRender event of
> the page is triggered the object is not there anymore.
>
>
>  Could someone advise on a better way of doing this?
>>
>
> You could not remove the object from the Environment or push and pop the
> object in the page, not in the component.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Using environment to access object in component from calling page

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 20 Jun 2011 07:49:01 -0300, Rizwan <ri...@gmail.com> wrote:

> Hi

Hi!

> I am trying to access a environment variable in a page.  The variable is  
> pushed onto the environment from the enclosed component.
> public class PageComponent {
>
> 	@Inject
> 	private Environment environment;
>
> 	@BeginRender
> 	Object pushObject() {
> 	    try {
>
> 			Display display = new Display();
>
> 			environment.push(Display.class, display);
> 	}
> 	
> 	@AfterRender
> 	void popObject () {
> 		environment.pop(Display.class);
> 	}
> }
> I have tried accessing this variable in BeginRender but does not work.   
> It seems like the AfterRender on the component is being called before  
> the page.

You're describing absolutely correct and expected behavior: your component  
is popping (removing) the Display object from the Environment after is  
rendered, but the page is still rendering, so when the @AfterRender event  
of the page is triggered the object is not there anymore.

> Could someone advise on a better way of doing this?

You could not remove the object from the Environment or push and pop the  
object in the page, not in the component.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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