You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2014/12/07 02:59:50 UTC

URL Rewrite with Form Validations

Hi, I'm doing some URL rewriting and I just discovered a new issue. I have
the following page rewritten to a new URL. "/sell/buildlisting/sell-car"
with "sell-car" being the context param and I'm rewriting the URL to
"/sell-car". When a form.error occures and the page reloads, it returns
"sell/buildlisting.form". How do I get the page to return "/sell-car.form"?

Re: URL Rewrite with Form Validations

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 05 Jan 2015 12:59:16 -0200, George Christman  
<gc...@cardaddy.com> wrote:

>> I'm not sure why
>
> I ended up finding an alternative to your simplelink approach that I
> seem to like much better. I'd be curious as to your thoughts.
>
> private Link buildLink(String basePath, PageRenderRequestParameters
> parameters, String target, String replacement, String concat) {
>     Link link =  
> componentEventLinkEncoder.createPageRenderLink(parameters);
>     return link.copyWithBasePath(basePath.replace(target, replacement));
> }

Hmmm, that code I wrote was written a long time ago, probably before Link  
had the copyWithBasePath() method.

> This was the example found of mapper at the bottom of this nabble
> link. I'm not sure what mapper is used for.

In that example, Mapper isn't a service. Instead, it's the class used as  
the distributed configuration of the PageRenderLinkTransformer  
implementation, which is also defined as a service. This way, you don't  
need to write code for simple x -> y URL rewrites.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: URL Rewrite with Form Validations

Posted by George Christman <gc...@cardaddy.com>.
I was a little confused, but I was able to resolve everything without issue.

On Mon, Jan 5, 2015 at 6:27 AM, Thiago H de Paula Figueiredo
<th...@gmail.com> wrote:
> On Mon, 29 Dec 2014 12:47:07 -0200, George Christman
> <gc...@cardaddy.com> wrote:
>
>> Hi Thiago, The following approach does indeed work, but I'd like to
>> verify it to be the correct approach for handling
>> ComponentEventLinkTransformer.
>
>
> Looks good to me. :)
>
>> SimpleLink is basically the class you
>> wrote, I'm just not sure if I should be using simplelink with
>> transformComponentEventLink.
>
>
> I'm not sure why

I ended up finding an alternative to your simplelink approach that I
seem to like much better. I'd be curious as to your thoughts.

private Link buildLink(String basePath, PageRenderRequestParameters
parameters, String target, String replacement, String concat) {
    Link link = componentEventLinkEncoder.createPageRenderLink(parameters);
    return link.copyWithBasePath(basePath.replace(target, replacement));
}

>
>> Also, is there a more efficient way of doing this?
>
>
> What do you mean by efficient?
>
>> One last thing, I see a Mapper service is being used in the nabble
>> example below. What does that service do?
>
>
> The example below doesn't have any signs of Mapper.

This was the example found of mapper at the bottom of this nabble
link. I'm not sure what mapper is used for.

PageRenderLinkTransformer {
    private List<Mapper> _mappers;
    private ComponentEventLinkEncoder _encoder;

    public StringMapperPageRenderLinkTransformer(List<Mapper> mappers,
ComponentEventLinkEncoder encoder) {
        _mappers = mappers;
        _encoder = encoder;
    }

    public Link transformPageRenderLink(Link defaultLink,
PageRenderRequestParameters parameters) {
        for (Mapper mapper : _mappers) {
            if (defaultLink.getBasePath().contains(mapper.getFrom())) {
                return
defaultLink.copyWithBasePath(defaultLink.getBasePath().replace(mapper.getFrom(),
mapper.getTo()));
            }
        }
        return null;
    }

    public PageRenderRequestParameters decodePageRenderRequest(Request
request) {
        for (Mapper mapper : _mappers) {
            if (request.getPath().contains(mapper.getTo())) {
                final String mapped =
request.getPath().replace(mapper.getTo(), mapper.getFrom());
                return _encoder.decodePageRenderRequest(
                        new DelegatingRequest(request) {
                            @Override
                            public String getPath() {
                                return mapped;
                            }
                        });
            }
        }
        return null;
    }
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

Thanks Thiago, happy new years.

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


Re: URL Rewrite with Form Validations

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 29 Dec 2014 12:47:07 -0200, George Christman  
<gc...@cardaddy.com> wrote:

> Hi Thiago, The following approach does indeed work, but I'd like to
> verify it to be the correct approach for handling
> ComponentEventLinkTransformer.

Looks good to me. :)

> SimpleLink is basically the class you
> wrote, I'm just not sure if I should be using simplelink with
> transformComponentEventLink.

I'm not sure why

> Also, is there a more efficient way of doing this?

What do you mean by efficient?

> One last thing, I see a Mapper service is being used in the nabble
> example below. What does that service do?

The example below doesn't have any signs of Mapper.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: URL Rewrite with Form Validations

Posted by George Christman <gc...@cardaddy.com>.
Hi Thiago, The following approach does indeed work, but I'd like to
verify it to be the correct approach for handling
ComponentEventLinkTransformer. SimpleLink is basically the class you
wrote, I'm just not sure if I should be using simplelink with
transformComponentEventLink.  Also, is there a more efficient way of
doing this?

One last thing, I see a Mapper service is being used in the nabble
example below. What does that service do?

Thanks

a couple of example sites I used
https://mail.google.com/mail/u/0/#search/label%3Atapestry+url+rewrite/14a22796d35779f0
http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/URL-Rewriting-in-Tapestry-5-2-td2467342.html


    @Override
    public Link transformComponentEventLink(Link defaultLink,
ComponentEventRequestParameters contextPathEncoder) {
        String basePath = defaultLink.getBasePath();
        if (basePath.contains("/checkbox")) {
            return SimpleLink(basePath.replace("checkbox", "testpage"));
        }
        return null;
    }

    @Override
    public ComponentEventRequestParameters
decodeComponentEventRequest(Request request) {
        final String path = request.getPath();

        if (path.startsWith("/testpage")) {
            return encoder.decodeComponentEventRequest(
                    new DelegatingRequest(request) {
                @Override
                public String getPath() {
                    return path.replace("/testpage", "/checkbox");
                }
            });
        }
        return null;
    }

On Sun, Dec 7, 2014 at 8:35 PM, George Christman
<gc...@cardaddy.com> wrote:
> Okay great, thanks Thiago.
>
> On Sun, Dec 7, 2014 at 7:30 AM, Thiago H de Paula Figueiredo
> <th...@gmail.com> wrote:
>>
>> On Sat, 06 Dec 2014 23:59:50 -0200, George Christman
>> <gc...@cardaddy.com> wrote:
>>
>>> Hi, I'm doing some URL rewriting and I just discovered a new issue. I
>>> have the following page rewritten to a new URL.
>>> "/sell/buildlisting/sell-car"
>>> with "sell-car" being the context param and I'm rewriting the URL to
>>> "/sell-car". When a form.error occures and the page reloads, it returns
>>> "sell/buildlisting.form". How do I get the page to return
>>> "/sell-car.form"?
>>
>>
>> For almost every incoming URL rewrite, you should write an outgoing
>> (Tapestry-generated) URL rewrite too, otherwise the non-rewritten URLs still
>> appear, as exemplified by your case described above. Specifically, you'll
>> need to write a ComponentEventLinkTransformer too (form submission URLs in
>> Tapestry are considered event links).
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Tapestry, Java and Hibernate consultant and developer
>> http://machina.com.br
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>
>
> --
> George Christman
> CEO
> www.CarDaddy.com
> P.O. Box 735
> Johnstown, New York
>



-- 
George Christman
CEO
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

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


Re: URL Rewrite with Form Validations

Posted by George Christman <gc...@cardaddy.com>.
Okay great, thanks Thiago.

On Sun, Dec 7, 2014 at 7:30 AM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Sat, 06 Dec 2014 23:59:50 -0200, George Christman <
> gchristman@cardaddy.com> wrote:
>
>  Hi, I'm doing some URL rewriting and I just discovered a new issue. I
>> have the following page rewritten to a new URL.
>> "/sell/buildlisting/sell-car"
>> with "sell-car" being the context param and I'm rewriting the URL to
>> "/sell-car". When a form.error occures and the page reloads, it returns
>> "sell/buildlisting.form". How do I get the page to return
>> "/sell-car.form"?
>>
>
> For almost every incoming URL rewrite, you should write an outgoing
> (Tapestry-generated) URL rewrite too, otherwise the non-rewritten URLs
> still appear, as exemplified by your case described above. Specifically,
> you'll need to write a ComponentEventLinkTransformer too (form submission
> URLs in Tapestry are considered event links).
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
George Christman
CEO
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

Re: URL Rewrite with Form Validations

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Sat, 06 Dec 2014 23:59:50 -0200, George Christman  
<gc...@cardaddy.com> wrote:

> Hi, I'm doing some URL rewriting and I just discovered a new issue. I  
> have the following page rewritten to a new URL.  
> "/sell/buildlisting/sell-car"
> with "sell-car" being the context param and I'm rewriting the URL to
> "/sell-car". When a form.error occures and the page reloads, it returns
> "sell/buildlisting.form". How do I get the page to return  
> "/sell-car.form"?

For almost every incoming URL rewrite, you should write an outgoing  
(Tapestry-generated) URL rewrite too, otherwise the non-rewritten URLs  
still appear, as exemplified by your case described above. Specifically,  
you'll need to write a ComponentEventLinkTransformer too (form submission  
URLs in Tapestry are considered event links).

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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