You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Sergey Didenko <se...@gmail.com> on 2009/06/25 16:51:50 UTC

Environmental annotation

Hi,

is it ok, that @Environmental does not work for user defined classes?

I expected it to work after reading
http://tapestry.apache.org/tapestry5.1/guide/env.html. But it does
not. I use environment.peek() instead.

Regards, Sergey.

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


Re: Environmental annotation

Posted by Howard Lewis Ship <hl...@gmail.com>.
@Environmental only works for component classes.

On Thu, Jun 25, 2009 at 7:51 AM, Sergey Didenko <se...@gmail.com>wrote:

> Hi,
>
> is it ok, that @Environmental does not work for user defined classes?
>
> I expected it to work after reading
> http://tapestry.apache.org/tapestry5.1/guide/env.html. But it does
> not. I use environment.peek() instead.
>
> Regards, Sergey.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship

Creator of Apache Tapestry
Director of Open Source Technology at Formos

Re: Environmental annotation

Posted by Sergey Didenko <se...@gmail.com>.
Thank for the tip, Kristian.

So probably this bug is not important then.

On Fri, Jun 26, 2009 at 9:56 AM, Kristian
Marinkovic<kr...@porsche.co.at> wrote:
> when compiled your inner class will get an own .class file
> in the components package. tapestry will load any class
> from the components package and enhance it.
>
> if you put your class into another package everything works
> as expected.
>
> so dont put any non component classes into the components
> package :)

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


Re: Environmental annotation

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
when compiled your inner class will get an own .class file
in the components package. tapestry will load any class 
from the components package and enhance it. 

if you put your class into another package everything works
as expected. 

so dont put any non component classes into the components
package :)

g,
kris




Sergey Didenko <se...@gmail.com> 
26.06.2009 08:39
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
Tapestry users <us...@tapestry.apache.org>
Kopie

Thema
Re: Environmental annotation







Howard, I don't want to be ontrusive, but I mean environmental services.

They are not obligated to be component classes. RenderSupport,
FormSupport, TabModel are not component classes, right? (
http://tapestry.apache.org/tapestry5.1/guide/env.html )

My report is related to a problem of fetching an environmental service
inside a component class. It does not contradict your words.

Let's rename InnerClass to InnerClassModel, OuterClass to
OuterClassModel if it makes the example clearer.

On Fri, Jun 26, 2009 at 12:53 AM, Howard Lewis Ship<hl...@gmail.com> 
wrote:
> @Environmental only works on component classes, period. If you are 
finding
> otherwise, there's something wrong with your tests or observations.

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



Re: Environmental annotation

Posted by Sergey Didenko <se...@gmail.com>.
Howard, I don't want to be ontrusive, but I mean environmental services.

They are not obligated to be component classes. RenderSupport,
FormSupport, TabModel are not component classes, right? (
http://tapestry.apache.org/tapestry5.1/guide/env.html )

My report is related to a problem of fetching an environmental service
inside a component class. It does not contradict your words.

Let's rename InnerClass to InnerClassModel, OuterClass to
OuterClassModel if it makes the example clearer.

On Fri, Jun 26, 2009 at 12:53 AM, Howard Lewis Ship<hl...@gmail.com> wrote:
> @Environmental only works on component classes, period. If you are finding
> otherwise, there's something wrong with your tests or observations.

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


Re: Environmental annotation

Posted by Howard Lewis Ship <hl...@gmail.com>.
@Environmental only works on component classes, period. If you are finding
otherwise, there's something wrong with your tests or observations.

On Thu, Jun 25, 2009 at 10:19 AM, Sergey Didenko
<se...@gmail.com>wrote:

> Well, I don't use @Environmental inside the inner class.
>
> Ok, then why @Environmental works for OuterClass which is placed outside
> .base, .page, .component packages?
>
> To reproduce just replace InnerClass for OuterClass in the previous
> example.
> And add OuterClass.java:
>
> package mytapp;
>
> public class OuterClass {
>  public String toString() {
> return "OuterClass";
> }
> }
>
>
> On Thu, Jun 25, 2009 at 7:53 PM, Howard Lewis Ship <hl...@gmail.com>
> wrote:
>
> > Inner classes are not component classes and are not transformed
> (component
> > class transformation is the hook that allows @Environmental to work).
> >
> >
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry
Director of Open Source Technology at Formos

Re: Environmental annotation

Posted by Sergey Didenko <se...@gmail.com>.
Well, I don't use @Environmental inside the inner class.

Ok, then why @Environmental works for OuterClass which is placed outside
.base, .page, .component packages?

To reproduce just replace InnerClass for OuterClass in the previous example.
And add OuterClass.java:

package mytapp;

public class OuterClass {
 public String toString() {
return "OuterClass";
}
}


On Thu, Jun 25, 2009 at 7:53 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> Inner classes are not component classes and are not transformed (component
> class transformation is the hook that allows @Environmental to work).
>
>

Re: Environmental annotation

Posted by Howard Lewis Ship <hl...@gmail.com>.
Inner classes are not component classes and are not transformed (component
class transformation is the hook that allows @Environmental to work).

On Thu, Jun 25, 2009 at 9:48 AM, Sergey Didenko <se...@gmail.com>wrote:

> Sure, I talk about component classes. Sorry for the unclear message.
>
> I played with the bug and reproduced it in the simple form.
>
> It happens when I put an inner class of the page into environment and
> use @Environmental.
> It does not happen when I refactor that inner class out of the page.
> It does not happen when I use environment.peek()
>
> --------------------------------------------------------------------
> SimplePage.java
> --------------------------------------------------------------------
>
> package mytapp.pages;
>
> import org.apache.tapestry5.ioc.annotations.Inject;
> import org.apache.tapestry5.services.Environment;
>
> public class SimplePage {
>
>        public class InnerClass {
>                public String toString() {
>                        return "InnerClass";
>                }
>        }
>
>        @Inject
>        private Environment environment;
>
>        void beginRender() {
>                environment.push( InnerClass.class, new InnerClass() );
>        }
>
>        void afterRender() {
>                environment.pop( InnerClass.class );
>        }
> }
>
> --------------------------------------------------------------------
> SimplePage.tml
> --------------------------------------------------------------------
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
> "http://www.w3.org/TR/html4/strict.dtd">
> <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
>  <head>
>    <title>Simple title</title>
>  </head>
>  <body>
>  <p>Simple text</p>
>
>  <p><t:SimpleComponent/></p>
>
>  </body>
> </html>
>
> --------------------------------------------------------------------
> SimpleComponent.java
> --------------------------------------------------------------------
>
> package mytapp.components;
>
> import mytapp.pages.SimplePage.InnerClass;
>
> import org.apache.tapestry5.MarkupWriter;
> import org.apache.tapestry5.annotations.Environmental;
>
> public class SimpleComponent {
>
>        @Environmental
>        private InnerClass innerClass;
>
>        // UNCOMMENT THIS TO WORK
>        // @Inject
>        // private Environment environment;
>
>        void beginRender( MarkupWriter writer ) {
>                // UNCOMMENT THIS TO WORK
>                // InnerClass innerClass = environment.peek(
> InnerClass.class );
>
>                writer.write( "SimpleComponent " + innerClass.toString() );
>         }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship

Creator of Apache Tapestry
Director of Open Source Technology at Formos

Re: Environmental annotation

Posted by Sergey Didenko <se...@gmail.com>.
Sure, I talk about component classes. Sorry for the unclear message.

I played with the bug and reproduced it in the simple form.

It happens when I put an inner class of the page into environment and
use @Environmental.
It does not happen when I refactor that inner class out of the page.
It does not happen when I use environment.peek()

--------------------------------------------------------------------
SimplePage.java
--------------------------------------------------------------------

package mytapp.pages;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Environment;

public class SimplePage {

	public class InnerClass {
		public String toString() {
			return "InnerClass";
		}
	}

	@Inject
	private Environment environment;

	void beginRender() {
		environment.push( InnerClass.class, new InnerClass() );
	}

	void afterRender() {
		environment.pop( InnerClass.class );
	}
}

--------------------------------------------------------------------
SimplePage.tml
--------------------------------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
  <head>
    <title>Simple title</title>
  </head>
  <body>
  <p>Simple text</p>

  <p><t:SimpleComponent/></p>

  </body>
</html>

--------------------------------------------------------------------
SimpleComponent.java
--------------------------------------------------------------------

package mytapp.components;

import mytapp.pages.SimplePage.InnerClass;

import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.Environmental;

public class SimpleComponent {

	@Environmental
	private InnerClass innerClass;

	// UNCOMMENT THIS TO WORK
	// @Inject
	// private Environment environment;

	void beginRender( MarkupWriter writer ) {
		// UNCOMMENT THIS TO WORK
		// InnerClass innerClass = environment.peek( InnerClass.class );

		writer.write( "SimpleComponent " + innerClass.toString() );
	}
}

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


Re: Environmental annotation

Posted by Onno Scheffers <on...@piraya.nl>.
>
> is it ok, that @Environmental does not work for user defined classes?
>
> I expected it to work after reading
> http://tapestry.apache.org/tapestry5.1/guide/env.html. But it does
> not. I use environment.peek() instead.



The answer should be in the very last paragraph of that page.


regards,

Onno