Thiago H. de Paula Figueiredo wrote:
> 
> Em Wed, 26 Aug 2009 11:29:42 -0300, ThirstyCrow <5451vs5...@gmail.com>  
> escreveu:
> 
>> if the getPageBlock() method works, everything will be ok. Here is where  
>> I got stuck. How to implement this method? Or is it possible to write  
>> such a method at all?
> 
> To get a page instance by name: ComponentSource.getPage() (this will  
> return a Component instance)
> To get a block from a Component: Component.getBlock();
> 
> -- 
> Thiago H. de Paula Figueiredo
> Independent Java consultant, developer, and instructor
> http://www.arsmachina.com.br/thiago
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 
> 
> 

Thanks, Thiago. With your help, now the method looks like this:

    Object onAction(String pageAndBlock) {
        String[] sb = pageAndBlock.split("/");
        if (request.isXHR()) {
            Block b =
cs.getPage(sb[0]).getComponentResources().getBlock(sb[1]);
            if (b != null) {
                return b;
            }
        }
        return sb[0];
    }

it works. However, the solution is still a little ugly. As you see, I have
to manually split the parameter to get the page and block names. I tried the
two-parameter method: Object onAction(String page, String block), but
tapestry failed to call it. Because when tapestry renders the page, it
encodes the slashes in the context attribute of the actionLinks, resulting a
link like "Index$002fcontent" rather than "Index/content" as I wrote in the
template. So when tapestry receives the request, it calls the one-parameter
handler, rather than the two method one. How to prevent this (encoding of
slashes) from happening?


-- 
View this message in context: 
http://www.nabble.com/T5.1%3A-Get-block-by-%28page-and-block%29-names--tp25151389p25166469.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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

Reply via email to