Define multiple @At annotations in one class.

120 views
Skip to first unread message

mmonti

unread,
Apr 16, 2013, 11:01:39 PM4/16/13
to google-s...@googlegroups.com
Hi guys,


I was trying to write a controller to render different templates.

I wrote the following controller: 

@At("/")
@Show("index.html")
public class Index {
    @Get
    @At("/locations")
    public Reply<?> locations() {
        return Reply.saying().ok().template(LocationPage.class).type("text/html");
    }
    @Get
    @At("/rooms")
    public Reply<?> rooms() {
        return Reply.saying().ok().template(RoomPage.class).type("text/html");
    }
}

LocationPage.java and RoomPage.java are annotated with @Show("<html-file>")

Should this work? Am i missing something?
I tried to move the @At annotations to a new classes (i.e: Locations.java and Rooms.java) and seems to work, but when I place the @At annotations in different methods I get a 404.

Sorry if this is a very basic question. I am just starting with sitebricks and I couldnt find a way to make it work.
Thanks!.
Mauro.

Dhanji R. Prasanna

unread,
Apr 16, 2013, 11:15:38 PM4/16/13
to google-s...@googlegroups.com
You try removing the @Show and replacing it with @Service. You cant mix template and headless web services (yet).

The recommended way to render templates is with the Templates API anyway.

return Reply.with(pageobject).template(...);


--
You received this message because you are subscribed to the Google Groups "Google Sitebricks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-sitebri...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

mmonti

unread,
Apr 17, 2013, 12:57:31 AM4/17/13
to google-s...@googlegroups.com
Hi dhanji,

Thanks for your quick reply. That change did the trick.
However I found something that I don't know if is a bug or is simply how it should work.

Basically I had to define the @At in the class Router with the value "app" as in the following example:

@At("/app") @Service
public class Router {
    @Get
    public Reply<HomePage> index() {
        return Reply.with(new HomePage()).template(HomePage.class).type("text/html");
    }
    @Get
    @At("/locations")
    public Reply<LocationPage> locations() {
        return Reply.with(new LocationPage()).template(LocationPage.class).type("text/html");
    }
    @Get
    @At("/rooms")
    public Reply<RoomPage> rooms() {
        return Reply.with(new RoomPage()).template(RoomPage.class).type("text/html");
    }
}
So now, requesting the path "localhost:8080/app" I get my HomePage, requesting "localhost:8080/app/locations", I get the correct LocationPage template.

But when I define "/" as a value in the @At annotation in Router class, requesting "localhost:8080/" I get the correct HomePage, but trying to request "localhost:8080/locations" I get a 404.

Just want to know if its the way that Sitebricks work.
Thanks!

Dhanji R. Prasanna

unread,
Apr 17, 2013, 1:23:27 AM4/17/13
to google-s...@googlegroups.com
Hmm yea I think so far we have only needed to do this subpath mapping for specific URIs.

I think if you had a subpath mapping for "/" then it becomes confusing when you have OTHER classes with "/blah" -- are they subpaths of "/" too? How about the data that exists in the parent "/" class? So I think it's better we don't support that use case.

That said we should report a nicer error than just 404.

Eric Charles (GMail)

unread,
Apr 18, 2013, 9:10:56 AM4/18/13
to google-s...@googlegroups.com
Could there be such issues only with conflicting @At annotation in the
same class (on class and method level)?

I have an app with @At("/") and @At("/blah") on different classes, and
it works fine.

Thx, Eric
> So now, requesting the path "*localhost:8080/app*" I get my
> HomePage, requesting "*localhost:8080/app/locations*", I get the
> correct LocationPage template.
>
> But when I define "/" as a value in the @At annotation in Router
> class, requesting "*localhost:8080/*" I get the correct HomePage,
> but trying to request "*localhost:8080/locations*" I get a 404.
>
> Just want to know if its the way that Sitebricks work.
> Thanks!
>
>
> On Tuesday, April 16, 2013 10:15:38 PM UTC-5, dhanji wrote:
>
> You try removing the @Show and replacing it with @Service. You
> cant mix template and headless web services (yet).
>
> The recommended way to render templates is with the Templates
> API anyway.
>
> return Reply.with(pageobject).__template(...);
>
>
> On Wed, Apr 17, 2013 at 8:31 AM, mmonti <monti...@gmail.com> wrote:
>
> Hi guys,
>
> Based on this post:
> https://groups.google.__com/forum/?fromgroups=#!__searchin/google-sitebricks/__subpath/google-sitebricks/__t42ntDiufDg/JZV5ShMgG_0J
> <https://groups.google.com/forum/?fromgroups=#!searchin/google-sitebricks/subpath/google-sitebricks/t42ntDiufDg/JZV5ShMgG_0J>
>
> I was trying to write a controller to render different
> templates.
>
> I wrote the following controller:
>
> @At("/")
> @Show("index.html")
> public class Index {
> @Get
> @At("/locations")
> public Reply<?> locations() {
> return
> Reply.saying().ok().template(__LocationPage.class).type("__text/html");
> }
> @Get
> @At("/rooms")
> public Reply<?> rooms() {
> return
> Reply.saying().ok().template(__RoomPage.class).type("text/__html");
> }
> }
>
> LocationPage.java and RoomPage.java are annotated with
> @Show("<html-file>")
>
> Should this work? Am i missing something?
> I tried to move the @At annotations to a new classes (i.e:
> Locations.java and Rooms.java) and seems to work, but when I
> place the @At annotations in different methods I get a 404.
>
> Sorry if this is a very basic question. I am just starting
> with sitebricks and I couldnt find a way to make it work.
> Thanks!.
> Mauro.
>
> --
> You received this message because you are subscribed to the
> Google Groups "Google Sitebricks" group.
> To unsubscribe from this group and stop receiving emails
> from it, send an email to google-sitebri...@__googlegroups.com.
>
> For more options, visit
> https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Google Sitebricks" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to google-sitebri...@googlegroups.com
> <mailto:google-sitebricks%2Bunsu...@googlegroups.com>.

Dhanji R. Prasanna

unread,
Apr 18, 2013, 11:05:53 AM4/18/13
to google-s...@googlegroups.com
Not really because the method @At are all sub paths of the class @At

Or did you mean something else?

The compiler should reject any paths that appear to conflict. But of course it cannot detect everything:

/blah/:any/id

will subsume

/blah/person/:any

if :any is exactly "id", if it appeared earlier in the dispatch order.

That's why any static paths always override dynamic paths.

Internally method @Ats are converted to longform:

@At("/person") class Person {
  @Get ....
  @At("/id") @Get ...
}

Will actually get rewritten as follows:

at("/person").show(Person.class);
at("/person/id").show(Person.class);

(module-style rules)



    For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to the Google
Groups "Google Sitebricks" group.
To unsubscribe from this group and stop receiving emails from it, send

For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to the Google Groups "Google Sitebricks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-sitebricks+unsubscribe@googlegroups.com.

Eric Charles (GMail)

unread,
Apr 18, 2013, 11:23:18 AM4/18/13
to google-s...@googlegroups.com
On 18/04/2013 16:05, Dhanji R. Prasanna wrote:
> Not really because the method @At are all sub paths of the class @At
>

oh, I once played with @At on methods but didn't not find my way.
I now see why : the method path are added to the class path. The
trailing is quite misleading in that case.

> Or did you mean something else?
>

Well, i just meant that I manage "/" and "/blah" paths on 2 different
classes and sitebricks behaves correctly as I could expect : "/" takes
predecence on "/blah", and that's what I want.

> The compiler should reject any paths that appear to conflict. But of
> course it cannot detect everything:
>
> /blah/:any/id
>
> will subsume
>
> /blah/person/:any
>
> if :any is exactly "id", if it appeared earlier in the dispatch order.
>
> That's why any static paths always override dynamic paths.
>

I also thought to failfast with a ConfusingPathException on startup, but
this probably not to do because as you said, it is really not easy for
the compiler to identify any confusion. It is even not easy for a human
with the example you gave.

Until now for me, sitebricks handles the path correctly.
Anyway, the developer should correctly design his path space.

> Internally method @Ats are converted to longform:
>
> @At("/person") class Person {
> @Get ....
> @At("/id") @Get ...
> }
>
> Will actually get rewritten as follows:
>
> at("/person").show(Person.class);
> at("/person/id").show(Person.class);
>

Ok, this confirms the method path are added to the class path.
This sounds fine, but when I did the test I started from the assumption
that the @At was imposing the full path (cfr. the trailing slash).

But I like that addition, it's just a matter of documenting it for the
user (just like many other things with sitebricks which has hidden gems,
not visible to the end-user).

> (module-style rules)
>
>
> On Thu, Apr 18, 2013 at 6:40 PM, Eric Charles (GMail)
> <eric.umg...@gmail.com <mailto:eric.umg...@gmail.com>> wrote:
>
> Could there be such issues only with conflicting @At annotation in
> the same class (on class and method level)?
>
> I have an app with @At("/") and @At("/blah") on different classes,
> and it works fine.
>
> Thx, Eric
>
>
>
> On 17/04/2013 06:23, Dhanji R. Prasanna wrote:
>
> Hmm yea I think so far we have only needed to do this subpath
> mapping
> for specific URIs.
>
> I think if you had a subpath mapping for "/" then it becomes
> confusing
> when you have OTHER classes with "/blah" -- are they subpaths of "/"
> too? How about the data that exists in the parent "/" class? So
> I think
> it's better we don't support that use case.
>
> That said we should report a nicer error than just 404.
>
>
> On Wed, Apr 17, 2013 at 10:27 AM, mmonti <monti...@gmail.com
> <mailto:monti...@gmail.com>
> <mailto:monti...@gmail.com <mailto:monti...@gmail.com>>__>
> wrote:
>
> Hi dhanji,
>
> Thanks for your quick reply. That change did the trick.
> However I found something that I don't know if is a bug or
> is simply
> how it should work.
>
> Basically I had to define the @At in the class Router with
> the value
> "app" as in the following example:
>
> @At("/app") @Service
> public class Router {
> @Get
> public Reply<HomePage> index() {
> return Reply.with(new
> HomePage()).template(HomePage.__class).type("text/html");
> }
> @Get
> @At("/locations")
> public Reply<LocationPage> locations() {
> return Reply.with(new
>
> LocationPage()).template(__LocationPage.class).type("__text/html");
> }
> @Get
> @At("/rooms")
> public Reply<RoomPage> rooms() {
> return Reply.with(new
> RoomPage()).template(RoomPage.__class).type("text/html");
> }
> }
> So now, requesting the path "*localhost:8080/app*" I get my
> HomePage, requesting "*localhost:8080/app/__locations*", I
> get the
>
> correct LocationPage template.
>
> But when I define "/" as a value in the @At annotation in
> Router
> class, requesting "*localhost:8080/*" I get the correct
> HomePage,
> but trying to request "*localhost:8080/locations*" I get a 404.
>
>
> Just want to know if its the way that Sitebricks work.
> Thanks!
>
>
> On Tuesday, April 16, 2013 10:15:38 PM UTC-5, dhanji wrote:
>
> You try removing the @Show and replacing it with
> @Service. You
> cant mix template and headless web services (yet).
>
> The recommended way to render templates is with the
> Templates
> API anyway.
>
> return Reply.with(pageobject).____template(...);
>
>
>
> On Wed, Apr 17, 2013 at 8:31 AM, mmonti
> <monti...@gmail.com <mailto:monti...@gmail.com>> wrote:
>
> Hi guys,
>
> Based on this post:
> https://groups.google.__com/__forum/?fromgroups=#!____searchin/google-sitebricks/____subpath/google-sitebricks/____t42ntDiufDg/JZV5ShMgG_0J
>
>
> <https://groups.google.com/__forum/?fromgroups=#!searchin/__google-sitebricks/subpath/__google-sitebricks/t42ntDiufDg/__JZV5ShMgG_0J
> <https://groups.google.com/forum/?fromgroups=#!searchin/google-sitebricks/subpath/google-sitebricks/t42ntDiufDg/JZV5ShMgG_0J>>
>
> I was trying to write a controller to render different
> templates.
>
> I wrote the following controller:
>
> @At("/")
> @Show("index.html")
> public class Index {
> @Get
> @At("/locations")
> public Reply<?> locations() {
> return
>
> Reply.saying().ok().template(____LocationPage.class).type("____text/html");
>
> }
> @Get
> @At("/rooms")
> public Reply<?> rooms() {
> return
>
> Reply.saying().ok().template(____RoomPage.class).type("text/____html");
>
> }
> }
>
> LocationPage.java and RoomPage.java are annotated with
> @Show("<html-file>")
>
> Should this work? Am i missing something?
> I tried to move the @At annotations to a new
> classes (i.e:
> Locations.java and Rooms.java) and seems to work,
> but when I
> place the @At annotations in different methods I
> get a 404.
>
> Sorry if this is a very basic question. I am just
> starting
> with sitebricks and I couldnt find a way to make it
> work.
> Thanks!.
> Mauro.
>
> --
> You received this message because you are
> subscribed to the
> Google Groups "Google Sitebricks" group.
> To unsubscribe from this group and stop receiving
> emails
> from it, send an email to
> google-sitebri...@__googlegrou__ps.com <http://googlegroups.com>.
>
> For more options, visit
> https://groups.google.com/____groups/opt_out
> <https://groups.google.com/__groups/opt_out>
> <https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>>.
>
>
>
>
> --
> You received this message because you are subscribed to the
> Google
> Groups "Google Sitebricks" group.
> To unsubscribe from this group and stop receiving emails
> from it,
> send an email to
> google-sitebricks+unsubscribe@__googlegroups.com
> <mailto:google-sitebricks%2Bunsu...@googlegroups.com>
> <mailto:google-sitebricks%__2Buns...@googlegroups.com
> <mailto:google-sitebricks%252Buns...@googlegroups.com>__>.
>
> For more options, visit
> https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Google Sitebricks" group.
> To unsubscribe from this group and stop receiving emails from
> it, send
> an email to google-sitebricks+unsubscribe@__googlegroups.com
> <mailto:google-sitebricks%2Bunsu...@googlegroups.com>.
> For more options, visit
> https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Google Sitebricks" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to google-sitebricks+unsubscribe@__googlegroups.com
> <mailto:google-sitebricks%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Google Sitebricks" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to google-sitebri...@googlegroups.com.

Dhanji R. Prasanna

unread,
Apr 18, 2013, 9:47:47 PM4/18/13
to google-s...@googlegroups.com
Yea would love some help documenting it :(

You can send a PR to GitHub.com/sitebricks

Thanks! 

Eric Charles (GMail)

unread,
Apr 19, 2013, 2:21:49 AM4/19/13
to google-s...@googlegroups.com
On 19/04/2013 02:47, Dhanji R. Prasanna wrote:
>
> Ok, this confirms the method path are added to the class path.
> This sounds fine, but when I did the test I started from the
> assumption that the @At was imposing the full path (cfr. the
> trailing slash).
>
> But I like that addition, it's just a matter of documenting it for
> the user (just like many other things with sitebricks which has
> hidden gems, not visible to the end-user).
>
>
> Yea would love some help documenting it :(
>
> You can send a PR to GitHub.com/sitebricks
>
> Thanks!
>

Can you please point me where the documentation reside?
I don't find it in https://github.com/dhanji/sitebricks repo.

Thx, Eric

Dhanji R. Prasanna

unread,
Apr 19, 2013, 2:58:32 AM4/19/13
to google-s...@googlegroups.com
it's in github.com/sitebricks not dhanji/sitebricks




--
You received this message because you are subscribed to the Google Groups "Google Sitebricks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-sitebricks+unsubscribe@googlegroups.com.

Eric Charles (GMail)

unread,
Apr 19, 2013, 3:03:00 AM4/19/13
to google-s...@googlegroups.com
Thx, will have a look,
Eric

On 19/04/2013 07:58, Dhanji R. Prasanna wrote:
> it's in github.com/sitebricks <http://github.com/sitebricks> not
> dhanji/sitebricks
>
>
>
>
> On Fri, Apr 19, 2013 at 11:51 AM, Eric Charles (GMail)
> <eric.umg...@gmail.com <mailto:eric.umg...@gmail.com>> wrote:
>
> On 19/04/2013 02:47, Dhanji R. Prasanna wrote:
>
>
> Ok, this confirms the method path are added to the class path.
> This sounds fine, but when I did the test I started from the
> assumption that the @At was imposing the full path (cfr. the
> trailing slash).
>
> But I like that addition, it's just a matter of documenting
> it for
> the user (just like many other things with sitebricks which has
> hidden gems, not visible to the end-user).
>
>
> Yea would love some help documenting it :(
>
> You can send a PR to GitHub.com/sitebricks
>
> Thanks!
>
>
> Can you please point me where the documentation reside?
> I don't find it in https://github.com/dhanji/__sitebricks
> <https://github.com/dhanji/sitebricks> repo.
>
> Thx, Eric
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Google Sitebricks" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to google-sitebricks+unsubscribe@__googlegroups.com
> <mailto:google-sitebricks%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Google Sitebricks" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to google-sitebri...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages