You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Dmitry Gusev <dm...@gmail.com> on 2010/04/01 15:50:44 UTC

Re: Page without markup

I don't like Dispatcher approach in one reason: using Dispatchers I will
have to route incoming requests myself and pick (instantiate?) concrete task
handler (and, maybe, manage their state?). In this case using pages is
preferred for me.
However I also refused to return StreamResponse from onActivate, since
keeping onActivate simple is a good approach I think.

For now I ended up with the following:

1. I declared custom metadata symbol (I named it NO_MARKUP) and annotated
all task handler pages with this metadata.
2. I contributed markupRenderer as a first renderer in chain and in there
I'm checking if page class contatins declared annotation. If it presents, I
simply return "<html></html>" as a response.

Here's the code in AppModule:

    /*
     * Support pages without markup
     */
    private static final String NO_MARKUP_SYMBOL = "NoMarkup";
    public static final String NO_MARKUP = NO_MARKUP_SYMBOL + "=true";

    public static void contributeFactoryDefaults(MappedConfiguration<String,
String> configuration)
    {
        configuration.add(NO_MARKUP_SYMBOL, "");
    }

    public void
contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter>
configuration,
                                         final MetaDataLocator
metaDataLocator,
                                         final ComponentEventLinkEncoder
linkEncoder,
                                         final RequestGlobals globals)
    {
        configuration.add(NO_MARKUP_SYMBOL,
            new MarkupRendererFilter()
            {
                @Override
                public void renderMarkup(MarkupWriter writer, MarkupRenderer
renderer) {
                    PageRenderRequestParameters parameters =
linkEncoder.decodePageRenderRequest(globals.getRequest());

                    boolean noMarkup =
metaDataLocator.findMeta(NO_MARKUP_SYMBOL, parameters.getLogicalPageName(),

Boolean.class);

                    if (noMarkup) {
                        //  Provide default (empty) markup
                        writer.element("html");
                    } else {
                        renderer.renderMarkup(writer);
                    }
                }
            }, "before:*");
    }

and an example of task class declaration:

@Meta(AppModule.NO_MARKUP)
public abstract class LongRunningQueryTask {


Hope this will help somebody else.

On Wed, Mar 31, 2010 at 15:44, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Wed, 31 Mar 2010 05:30:49 -0300, Dmitry Gusev <dm...@gmail.com>
> wrote:
>
>  Can't get it working with Dispatcher.
>>
>
> Take a look at
> http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher.
>
>
>  Where should I plug new dispatcher
>>
>
> It must be contributed to the MasterDispatcher service.
>
>
>  and what should a dispatcher do?
>>
>
> A dispatcher is a class that handles requests and generates a response. In
> Tapestry, it's the concept more similar to a servlet. In your case, as you
> don't need to generate a response, it would be a better fit than a page.
>
>
>  Do you propose to replaces pages with
>> dispatchers?
>>
>
> No, just to handle URLs that don't generate a response.
>
>
>  Or just make dispatcher which somehow says to Tapestry that
>> specified page doesn't contain any template file?
>>
>
> No. A dispatcher is completely different from a page.
>
>
>  I tried to add new dispatcher to both "before:PageRender" and
>> "after:PageRender" but didn't have any success. The one in
>> "after:PageRender" never ever invoked. And handlign request in
>> "before:PageRender" prevents executing page's onActivate at all.
>>
>
> In this case, the dispatcher would replace the page that handles the GAE
> callback. Don't forget that the boolean dispatch(Request request, Response
> response) throws IOException method must return false for requests not
> really handled by the dispatcher.
>
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, software architect and developer, 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
>
>


-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com

Re: Page without markup

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
(Answering again as I accidently hit the send button)

On Thu, 01 Apr 2010 10:50:44 -0300, Dmitry Gusev <dm...@gmail.com>  
wrote:

> I don't like Dispatcher approach in one reason: using Dispatchers I will
> have to route incoming requests myself

That's right.

> and pick (instantiate?) concrete task handler

If you declare your dispatcher as a Tapestry-IoC service, you can inject  
whatever you want.

> (and, maybe, manage their state?).

Task handlers tend to be stateless. If you want to handle @SessionState  
objects, use the ApplicationStateManager service.

> In this case using pages is preferred for me.

Point taken. :)

> However I also refused to return StreamResponse from onActivate, since
> keeping onActivate simple is a good approach I think.

Maybe Tapestry itself could have some return type or value that means that  
the page doesn't generate a response.

> For now I ended up with the following:
>
> 1. I declared custom metadata symbol (I named it NO_MARKUP) and annotated
> all task handler pages with this metadata.
> 2. I contributed markupRenderer as a first renderer in chain and in there
> I'm checking if page class contatins declared annotation. If it  
> presents, I simply return "<html></html>" as a response.

Nice solution! :)

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, 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: Page without markup

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 01 Apr 2010 10:50:44 -0300, Dmitry Gusev <dm...@gmail.com>  
wrote:

> I don't like Dispatcher approach in one reason: using Dispatchers I will
> have to route incoming requests myself

That's right.

> and pick (instantiate?) concrete task handler (and, maybe, manage their  
> state?). In this case using pages is
> preferred for me.
> However I also refused to return StreamResponse from onActivate, since
> keeping onActivate simple is a good approach I think.
>
> For now I ended up with the following:
>
> 1. I declared custom metadata symbol (I named it NO_MARKUP) and annotated
> all task handler pages with this metadata.
> 2. I contributed markupRenderer as a first renderer in chain and in there
> I'm checking if page class contatins declared annotation. If it  
> presents, I
> simply return "<html></html>" as a response.
>
> Here's the code in AppModule:
>
>     /*
>      * Support pages without markup
>      */
>     private static final String NO_MARKUP_SYMBOL = "NoMarkup";
>     public static final String NO_MARKUP = NO_MARKUP_SYMBOL + "=true";
>
>     public static void  
> contributeFactoryDefaults(MappedConfiguration<String,
> String> configuration)
>     {
>         configuration.add(NO_MARKUP_SYMBOL, "");
>     }
>
>     public void
> contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter>
> configuration,
>                                          final MetaDataLocator
> metaDataLocator,
>                                          final ComponentEventLinkEncoder
> linkEncoder,
>                                          final RequestGlobals globals)
>     {
>         configuration.add(NO_MARKUP_SYMBOL,
>             new MarkupRendererFilter()
>             {
>                 @Override
>                 public void renderMarkup(MarkupWriter writer,  
> MarkupRenderer
> renderer) {
>                     PageRenderRequestParameters parameters =
> linkEncoder.decodePageRenderRequest(globals.getRequest());
>
>                     boolean noMarkup =
> metaDataLocator.findMeta(NO_MARKUP_SYMBOL,  
> parameters.getLogicalPageName(),
>
> Boolean.class);
>
>                     if (noMarkup) {
>                         //  Provide default (empty) markup
>                         writer.element("html");
>                     } else {
>                         renderer.renderMarkup(writer);
>                     }
>                 }
>             }, "before:*");
>     }
>
> and an example of task class declaration:
>
> @Meta(AppModule.NO_MARKUP)
> public abstract class LongRunningQueryTask {
>
>
> Hope this will help somebody else.
>
> On Wed, Mar 31, 2010 at 15:44, Thiago H. de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
>> On Wed, 31 Mar 2010 05:30:49 -0300, Dmitry Gusev  
>> <dm...@gmail.com>
>> wrote:
>>
>>  Can't get it working with Dispatcher.
>>>
>>
>> Take a look at
>> http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher.
>>
>>
>>  Where should I plug new dispatcher
>>>
>>
>> It must be contributed to the MasterDispatcher service.
>>
>>
>>  and what should a dispatcher do?
>>>
>>
>> A dispatcher is a class that handles requests and generates a response.  
>> In
>> Tapestry, it's the concept more similar to a servlet. In your case, as  
>> you
>> don't need to generate a response, it would be a better fit than a page.
>>
>>
>>  Do you propose to replaces pages with
>>> dispatchers?
>>>
>>
>> No, just to handle URLs that don't generate a response.
>>
>>
>>  Or just make dispatcher which somehow says to Tapestry that
>>> specified page doesn't contain any template file?
>>>
>>
>> No. A dispatcher is completely different from a page.
>>
>>
>>  I tried to add new dispatcher to both "before:PageRender" and
>>> "after:PageRender" but didn't have any success. The one in
>>> "after:PageRender" never ever invoked. And handlign request in
>>> "before:PageRender" prevents executing page's onActivate at all.
>>>
>>
>> In this case, the dispatcher would replace the page that handles the GAE
>> callback. Don't forget that the boolean dispatch(Request request,  
>> Response
>> response) throws IOException method must return false for requests not
>> really handled by the dispatcher.
>>
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
>> and instructor
>> Owner, software architect and developer, 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
>>
>>
>
>


-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
Coordenador e professor da Especialização em Engenharia de Software com  
Ênfase em Java da Faculdade Pitágoras
Consultor, desenvolvedor e instrutor em Java, Tapestry e Hibernate
Sócio, 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