You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by shinlang <sa...@gameforge.de> on 2010/10/22 14:25:03 UTC

Annotations and ComponentRequestFilter Problem

Hi,

i'm having a problem using custom annotations and a ComponentRequestFilter.
I am defining my own class annotation (TestAnnotation) and a test class
(Index) that uses this annotation.

In my ComponentRequestFilter however, when i am checking the page class (via
componentSource.getPage().getClass(), it doesn't have the annotation.
However, When i try to read the annotation on the class itself (using
Index.class), it's working.

Therefore i assume this has something to do with class transformation in
tapestry, it seems like the class annotation isn't present in the
transformed class anymore.

I have of course read the article at
http://tapestryjava.blogspot.com/2009/12/securing-tapestry-pages-with.html,
and i can't see any difference:

Component page = componentSource.getPage(pageName);
if (! page.getClass().isAnnotationPresent(RequiresLogin.class)) {
	return false;
}

is exactly what I'm using (except for the different variable names...), it
just doesn't work.

When i try 

Index.class.isAnnotationPresent(TestAnnotation.class)

it returns true, just as expected.

If anyone got a good idea, i'd be very thankful.

Regards,
Sascha
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/Annotations-and-ComponentRequestFilter-Problem-tp3232159p3232159.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: Annotations and ComponentRequestFilter Problem

Posted by shinlang <sa...@gameforge.de>.
Hi taha,

you can find an example project here:
http://satansoft.de/tapestry/annotationtest.zip

It uses a very simple setup to show the problem. In TestFilter.java in the
annotationTest() method you can see that the upper test case is not working,
but the lower case is working well.

Regards,
Sascha
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/Annotations-and-ComponentRequestFilter-Problem-tp3232159p3232236.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: Annotations and ComponentRequestFilter Problem

Posted by Taha Hafeez <ta...@gmail.com>.
Can you share the code

taha


On Fri, Oct 22, 2010 at 5:55 PM, shinlang <sa...@gameforge.de>wrote:

>
> Hi,
>
> i'm having a problem using custom annotations and a ComponentRequestFilter.
> I am defining my own class annotation (TestAnnotation) and a test class
> (Index) that uses this annotation.
>
> In my ComponentRequestFilter however, when i am checking the page class
> (via
> componentSource.getPage().getClass(), it doesn't have the annotation.
> However, When i try to read the annotation on the class itself (using
> Index.class), it's working.
>
> Therefore i assume this has something to do with class transformation in
> tapestry, it seems like the class annotation isn't present in the
> transformed class anymore.
>
> I have of course read the article at
> http://tapestryjava.blogspot.com/2009/12/securing-tapestry-pages-with.html
> ,
> and i can't see any difference:
>
> Component page = componentSource.getPage(pageName);
> if (! page.getClass().isAnnotationPresent(RequiresLogin.class)) {
>        return false;
> }
>
> is exactly what I'm using (except for the different variable names...), it
> just doesn't work.
>
> When i try
>
> Index.class.isAnnotationPresent(TestAnnotation.class)
>
> it returns true, just as expected.
>
> If anyone got a good idea, i'd be very thankful.
>
> Regards,
> Sascha
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Annotations-and-ComponentRequestFilter-Problem-tp3232159p3232159.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: Annotations and ComponentRequestFilter Problem

Posted by shinlang <sa...@gameforge.de>.
Hi Taha, Hi Thiago,

Thanks a lot for your reply, it's working perfectly! And besides, this
surely gave me some more basic understanding on how tapestry works.

Have a nice day,
cheers,
Sascha
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/Annotations-and-ComponentRequestFilter-Problem-tp3232159p3235337.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: T5.1 IFrame and src context

Posted by Richard Hill <ri...@su3analytics.com>.
To answer my own question:

@Inject
private PageRenderLinkSource prls;


public String getFrameSrc() {
		
Link l = prls.createPageRenderLinkWithContext
                      (DiffReportHTML.class,getContext());
		
	return l.toAbsoluteURI();
		
}

Sorry for unnecessary post (late friday afternoon, brain switching
off) :)


-----Original Message-----
From: Richard Hill <ri...@su3analytics.com>
Reply-to: rich@su3analytics.com
To: Tapestry users <us...@tapestry.apache.org>
Subject: T5.1 IFrame and src context
Date: Fri, 22 Oct 2010 16:30:58 +0100

Hi All,

I have an <iframe> in my T5.1 page. The src is another page served by
the same tapestry webapp. The page to be loaded in the <iframe> takes 2
parameters, a string and an int, as activation context. How do I
construct the value of the src to correctly link to the page with the
correctly formatted activation parameters?

Thanks very much,

Richard

 



---------------------------------------------------------------------
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


T5.1 IFrame and src context

Posted by Richard Hill <ri...@su3analytics.com>.
Hi All,

I have an <iframe> in my T5.1 page. The src is another page served by
the same tapestry webapp. The page to be loaded in the <iframe> takes 2
parameters, a string and an int, as activation context. How do I
construct the value of the src to correctly link to the page with the
correctly formatted activation parameters?

Thanks very much,

Richard

 



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


Re: Annotations and ComponentRequestFilter Problem

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 22 Oct 2010 12:10:38 -0200, Taha Hafeez <ta...@gmail.com>  
wrote:

> Just move the annotation out of the pages package.

This is one of the most common pitfalls Tapestry beginners fall: never  
never never put something in a pages, components or mixins package that  
isn't a page, component or mixin.

> Although I don't know the internals of tapestry that well but I think
> because pages and components packages have live reloading they may be  
> loaded from different classloaders...

Taha, you're absolutely correct. ;)

-- 
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: Annotations and ComponentRequestFilter Problem

Posted by Taha Hafeez <ta...@gmail.com>.
Just move the annotation out of the pages package.

Although I don't know the internals of tapestry that well but I think
because pages and components packages have live reloading they may be loaded
from different classloaders...

regards
Taha


On Fri, Oct 22, 2010 at 7:19 PM, shinlang <sa...@gameforge.de>wrote:

>
> Hi Thiago,
>
> thanks for your reply. I will certainly give that a try, but i won't be in
> the office until monday. I'm not sure, if i stated my problem right (as i'm
> quite new to tapestry). I am not dynamically adding the annotation to the
> class, as far as i can see, so getting it from the component source should
> work, shouldn't it?
>
> There is a test project that desscribes the problem, it can be found at
> http://satansoft.de/tapestry/annotationtest.zip.
>
> In the TestFilter class you can see how i try to get the annotation from
> the
> page.
>
> Btw, i'm using Tapestry 5.2...
>
> Regards,
> Sascha
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Annotations-and-ComponentRequestFilter-Problem-tp3232159p3232277.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: Annotations and ComponentRequestFilter Problem

Posted by shinlang <sa...@gameforge.de>.
Hi Thiago,

thanks for your reply. I will certainly give that a try, but i won't be in
the office until monday. I'm not sure, if i stated my problem right (as i'm
quite new to tapestry). I am not dynamically adding the annotation to the
class, as far as i can see, so getting it from the component source should
work, shouldn't it? 

There is a test project that desscribes the problem, it can be found at
http://satansoft.de/tapestry/annotationtest.zip.

In the TestFilter class you can see how i try to get the annotation from the
page.

Btw, i'm using Tapestry 5.2...

Regards,
Sascha
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/Annotations-and-ComponentRequestFilter-Problem-tp3232159p3232277.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: Annotations and ComponentRequestFilter Problem

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 22 Oct 2010 10:25:03 -0200, shinlang <sa...@gameforge.de>  
wrote:

> Hi,

Hi!

> I have of course read the article at
> http://tapestryjava.blogspot.com/2009/12/securing-tapestry-pages-with.html,
> and i can't see any difference:
>
> Component page = componentSource.getPage(pageName);
> if (! page.getClass().isAnnotationPresent(RequiresLogin.class)) {
> 	return false;
> }

This doesn't work if you add the annotation after you started the  
application. Another way of doing that, which works well with live class  
reloading (you add, remove or change an annotation and it automatically  
works) is using a worker. This is the one which handles the @Secure  
annotation in Tapestry:

public class SecureWorker implements ComponentClassTransformWorker
{
     public void transform(ClassTransformation transformation,  
MutableComponentModel model)
     {
         Secure secure = transformation.getAnnotation(Secure.class);

         if (secure != null)
             model.setMeta(MetaDataConstants.SECURE_PAGE, "true");
     }
}

You can get the ComponentModel of a given page or component instance using  
getComponentResources().getComponentModel().

-- 
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