Re: Hyphens in URL possible?

2016-05-02 Thread Stephen Nutbrown
Carlos,

Many thanks for this - this is absolutely fantastic. Thank you for the
effort of posting this and the help. It'll take me a little bit of time to
digest it and fully understand how I can apply this to our exact project,
but it looks like everything I need is here!

Many thanks again, I really appreciate it.
Stephen Nutbrown

On 2 May 2016 at 11:38, Carlos Montero Canabal <
carlosmonterocana...@gmail.com> wrote:

> Yes. I do it in many webapps.
>
> AppModule:
>
> @Contribute(PageRenderLinkTransformer.class)
> @Primary
> public static void provideURLRewriting(final
> OrderedConfiguration configuration) {
>
> configuration.addInstance(
> “MyLinkTransformer", MyLinkTransformer.class);
> }
>
> For simple pages (without context), I have a utility class with
> logicalPage name and the names into various languages (Spanish and English
> in the example) for better SEO on each language:
>
> private class PageLinkTransFormer {
>
> private final String logical;
>
> private final String linkEs;
>
> private final String linkEn;
>
> public PageLinkTransFormer(final String logical, final
> String linkEs, final String linkEn) {
> super();
> this.logical = logical;
> this.linkEs = linkEs;
> this.linkEn = linkEn;
> }
>
> public String getLogical() {
> return logical;
> }
>
> public String getLinkEs() {
> return linkEs;
> }
>
> public String getLinkEn() {
> return linkEn;
> }
>
> }
>
>
> And the MyLinkTransformer Service (in the example, I have the pages
> DevolucionesPage, AvisoLegalPage and SizeGuidePage):
>
> public class MyLinkTransformer implements
> PageRenderLinkTransformer {
>
> private static final String DEVOLUCIONES_LOGICAL_PAGE_NAME =
> "Devoluciones";
>
> private static final String DEVOLUCIONES_PAGE_URL_ES =
> "/envios-devoluciones-cuidados";
>
> private static final String DEVOLUCIONES_PAGE_URL_EN =
> "/delivery-return-cares";
>
> private static final String AVISO_LEGAL_LOGICAL_PAGE_NAME =
> "AvisoLegal";
>
> private static final String AVISO_LEGAL_PAGE_URL_ES =
> "/aviso-legal";
>
> private static final String AVISO_LEGAL_PAGE_URL_EN =
> "/disclaimer";
>
> private static final String SIZE_GUIDE_LOGICAL_PAGE_NAME =
> "SizeGuide";
>
> private static final String SIZE_GUIDE_PAGE_URL_ES =
> "/guia-tallas";
>
> private static final String SIZE_GUIDE_PAGE_URL_EN = "/size-guide";
>
> private final List links;
>
> @Inject
> private PageRenderLinkSource pageRenderLinkSource;
>
> @Inject
> private ContextValueEncoder contextValueEncoder;
>
> @Inject
> private ThreadLocale threadLocale;
>
> @Inject
> private PersistentLocale persistentLocale;
>
> public MyLinkTransformer() {
>
> links = new
> ArrayList();
>
> links.add(new PageLinkTransFormer(
> DEVOLUCIONES_LOGICAL_PAGE_NAME,
> DEVOLUCIONES_PAGE_URL_ES,
> DEVOLUCIONES_PAGE_URL_EN));
>
> links.add(new PageLinkTransFormer(
> AVISO_LEGAL_LOGICAL_PAGE_NAME,
> AVISO_LEGAL_PAGE_URL_ES,
> AVISO_LEGAL_PAGE_URL_EN));
>
> links.add(new PageLinkTransFormer(
> SIZE_GUIDE_LOGICAL_PAGE_NAME,
> SIZE_GUIDE_PAGE_URL_ES,
> SIZE_GUIDE_PAGE_URL_EN));
>
> }
>
> @Override
> public Link transformPageRenderLink(final Link defaultLink, final
> PageRenderRequestParameters parameters) {
>
> LOGGER.trace("transformPageRenderLink {} ({})",
> parameters.getLogicalPageName(), defaultLink.toAbsoluteURI());
>
> final String locale = threadLocale.getLocale().toString();
> for (final PageLinkTransFormer link : links) {
> if
> (link.getLogical().equals(parameters.getLogicalPageName())) {
> if ("es".equals(locale)) {
> return
> defaultLink.copyWithBasePath(link.getLinkEs());
> }
> else {
> return
> defaultLink.copyWithBasePath(link.getLinkEn());
> }
> }
> }
>
> return null;
> }
>
> @Override
> public PageRenderRequestParameters decodePageRenderRequest(final
> Reques

Re: Changing Grid.currentPage persistency to flash

2016-05-02 Thread Barry Books
I have not changed it to flash but I did write a persistence strategy to
put the values is the url. I would agree that persisting the values in the
session has issues. The only problem with using the URL is if you have more
than one grid on a page you have to name the query parameters correctly.
Using the URL makes the grid stateless and bookmarkable.

On Monday, May 2, 2016, Davide Vecchi  wrote:

> Thanks, I didn't know about Persistence Strategy Inheritance, it's good
> info. In this specific case I probably will not need to use it because we
> have already heavily customized the grid code, but I will certainly go for
> this inheritance mechanism when I need to control persistency on a
> component basis for non-customized components.
>
> If anyone still has any observation, opinion or just guess about whether
> using flash persistency for the Grid.currentPage instance field might not
> be that good an idea I'd still like to hear about that.
>
>
> -Original Message-
> From: Chris Poulsen [mailto:mailingl...@nesluop.dk ]
> Sent: Monday, May 2, 2016 13:11
> To: Tapestry users >
> Subject: Re: Changing Grid.currentPage persistency to flash
>
> I haven't used the grid with flash persistence, so I cannot comment on
> that.
>
> But I just want to let you know that you can control the behavior of
> @Persist inside the Grid using "Persistence Strategy Inheritance" (
> http://tapestry.apache.org/persistent-page-data.html ) without having to
> alter the component itself.
>
> --
> Chris
>
> On Mon, May 2, 2016 at 11:12 AM, Davide Vecchi >
> wrote:
>
> > Hi everybody
> >
> > I see that the instance field that holds the current page number of a
> > grid
> > (org.apache.tapestry5.corelib.components.Grid.currentPage) is
> > annotated with @Persist .
> >
> > This has the probably desirable effect that f.ex. if I am on webpage A
> > and it has a grid and I browse to its page #2 and then I go to another
> > webpage and then I go back to webpage A its grid is still on its page
> > #2 where I had left it.
> >
> > However in my case this is not desirable and I would prefer that the
> > grid page number is not remembered across different webpages.
> >
> > Removing the @Persist annotation of Grid.currentPage instance field
> > altogether would cause the impossibility to browse grid pages at all
> > because the grid pager does a page reload and this loses the
> > currentPage value, but persisting that value just until the next
> > request - to preserve that value during the page reload  - seems to
> > work fine: I changed the annotation from
> >
> > @Persist
> >
> > to
> >
> > @Persist(PersistenceConstants.FLASH)
> >
> > and I'm testing my pages to make sure this works. However I am also
> > wondering if in theory changing that persistency to flash might be a
> > bad idea for reasons that I don't know and that my tests so far are
> > not showing. Does anyone have any opinion about this ?
> >
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> 
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 
>


RE: Changing Grid.currentPage persistency to flash

2016-05-02 Thread Davide Vecchi
Thanks, I didn't know about Persistence Strategy Inheritance, it's good info. 
In this specific case I probably will not need to use it because we have 
already heavily customized the grid code, but I will certainly go for this 
inheritance mechanism when I need to control persistency on a component basis 
for non-customized components.

If anyone still has any observation, opinion or just guess about whether using 
flash persistency for the Grid.currentPage instance field might not be that 
good an idea I'd still like to hear about that.
  

-Original Message-
From: Chris Poulsen [mailto:mailingl...@nesluop.dk] 
Sent: Monday, May 2, 2016 13:11
To: Tapestry users 
Subject: Re: Changing Grid.currentPage persistency to flash

I haven't used the grid with flash persistence, so I cannot comment on that.

But I just want to let you know that you can control the behavior of @Persist 
inside the Grid using "Persistence Strategy Inheritance" ( 
http://tapestry.apache.org/persistent-page-data.html ) without having to alter 
the component itself.

--
Chris

On Mon, May 2, 2016 at 11:12 AM, Davide Vecchi  wrote:

> Hi everybody
>
> I see that the instance field that holds the current page number of a 
> grid
> (org.apache.tapestry5.corelib.components.Grid.currentPage) is 
> annotated with @Persist .
>
> This has the probably desirable effect that f.ex. if I am on webpage A 
> and it has a grid and I browse to its page #2 and then I go to another 
> webpage and then I go back to webpage A its grid is still on its page 
> #2 where I had left it.
>
> However in my case this is not desirable and I would prefer that the 
> grid page number is not remembered across different webpages.
>
> Removing the @Persist annotation of Grid.currentPage instance field 
> altogether would cause the impossibility to browse grid pages at all 
> because the grid pager does a page reload and this loses the 
> currentPage value, but persisting that value just until the next 
> request - to preserve that value during the page reload  - seems to 
> work fine: I changed the annotation from
>
> @Persist
>
> to
>
> @Persist(PersistenceConstants.FLASH)
>
> and I'm testing my pages to make sure this works. However I am also 
> wondering if in theory changing that persistency to flash might be a 
> bad idea for reasons that I don't know and that my tests so far are 
> not showing. Does anyone have any opinion about this ?
>

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


Re: Changing Grid.currentPage persistency to flash

2016-05-02 Thread Chris Poulsen
I haven't used the grid with flash persistence, so I cannot comment on that.

But I just want to let you know that you can control the behavior of
@Persist inside the Grid using "Persistence Strategy Inheritance" (
http://tapestry.apache.org/persistent-page-data.html ) without having to
alter the component itself.

--
Chris

On Mon, May 2, 2016 at 11:12 AM, Davide Vecchi  wrote:

> Hi everybody
>
> I see that the instance field that holds the current page number of a grid
> (org.apache.tapestry5.corelib.components.Grid.currentPage) is annotated
> with @Persist .
>
> This has the probably desirable effect that f.ex. if I am on webpage A and
> it has a grid and I browse to its page #2 and then I go to another webpage
> and then I go back to webpage A its grid is still on its page #2 where I
> had left it.
>
> However in my case this is not desirable and I would prefer that the grid
> page number is not remembered across different webpages.
>
> Removing the @Persist annotation of Grid.currentPage instance field
> altogether would cause the impossibility to browse grid pages at all
> because the grid pager does a page reload and this loses the currentPage
> value, but persisting that value just until the next request - to preserve
> that value during the page reload  - seems to work fine: I changed the
> annotation from
>
> @Persist
>
> to
>
> @Persist(PersistenceConstants.FLASH)
>
> and I'm testing my pages to make sure this works. However I am also
> wondering if in theory changing that persistency to flash might be a bad
> idea for reasons that I don't know and that my tests so far are not
> showing. Does anyone have any opinion about this ?
>


Re: Hyphens in URL possible?

2016-05-02 Thread Carlos Montero Canabal
Yes. I do it in many webapps.

AppModule:

@Contribute(PageRenderLinkTransformer.class)
@Primary
public static void provideURLRewriting(final 
OrderedConfiguration configuration) {

configuration.addInstance(
“MyLinkTransformer", MyLinkTransformer.class);
}

For simple pages (without context), I have a utility class with logicalPage 
name and the names into various languages (Spanish and English in the example) 
for better SEO on each language:

private class PageLinkTransFormer {

private final String logical;

private final String linkEs;

private final String linkEn;

public PageLinkTransFormer(final String logical, final String 
linkEs, final String linkEn) {
super();
this.logical = logical;
this.linkEs = linkEs;
this.linkEn = linkEn;
}

public String getLogical() {
return logical;
}

public String getLinkEs() {
return linkEs;
}

public String getLinkEn() {
return linkEn;
}

}


And the MyLinkTransformer Service (in the example, I have the pages 
DevolucionesPage, AvisoLegalPage and SizeGuidePage):

public class MyLinkTransformer implements PageRenderLinkTransformer {

private static final String DEVOLUCIONES_LOGICAL_PAGE_NAME = 
"Devoluciones";

private static final String DEVOLUCIONES_PAGE_URL_ES = 
"/envios-devoluciones-cuidados";

private static final String DEVOLUCIONES_PAGE_URL_EN = 
"/delivery-return-cares";

private static final String AVISO_LEGAL_LOGICAL_PAGE_NAME = 
"AvisoLegal";

private static final String AVISO_LEGAL_PAGE_URL_ES = "/aviso-legal";

private static final String AVISO_LEGAL_PAGE_URL_EN = "/disclaimer";

private static final String SIZE_GUIDE_LOGICAL_PAGE_NAME = "SizeGuide";

private static final String SIZE_GUIDE_PAGE_URL_ES = "/guia-tallas";

private static final String SIZE_GUIDE_PAGE_URL_EN = "/size-guide";

private final List links;

@Inject
private PageRenderLinkSource pageRenderLinkSource;

@Inject
private ContextValueEncoder contextValueEncoder;

@Inject
private ThreadLocale threadLocale;

@Inject
private PersistentLocale persistentLocale;

public MyLinkTransformer() {

links = new ArrayList();

links.add(new PageLinkTransFormer(
DEVOLUCIONES_LOGICAL_PAGE_NAME,
DEVOLUCIONES_PAGE_URL_ES,
DEVOLUCIONES_PAGE_URL_EN));

links.add(new PageLinkTransFormer(
AVISO_LEGAL_LOGICAL_PAGE_NAME,
AVISO_LEGAL_PAGE_URL_ES,
AVISO_LEGAL_PAGE_URL_EN));

links.add(new PageLinkTransFormer(
SIZE_GUIDE_LOGICAL_PAGE_NAME,
SIZE_GUIDE_PAGE_URL_ES,
SIZE_GUIDE_PAGE_URL_EN));

}

@Override
public Link transformPageRenderLink(final Link defaultLink, final 
PageRenderRequestParameters parameters) {

LOGGER.trace("transformPageRenderLink {} ({})", 
parameters.getLogicalPageName(), defaultLink.toAbsoluteURI());

final String locale = threadLocale.getLocale().toString();
for (final PageLinkTransFormer link : links) {
if 
(link.getLogical().equals(parameters.getLogicalPageName())) {
if ("es".equals(locale)) {
return 
defaultLink.copyWithBasePath(link.getLinkEs());
}
else {
return 
defaultLink.copyWithBasePath(link.getLinkEn());
}
}
}

return null;
}

@Override
public PageRenderRequestParameters decodePageRenderRequest(final 
Request request) {

String requestPath = request.getPath();
if (persistentLocale.isSet()) {
requestPath = requestPath.substring(3);
}

for (final PageLinkTransFormer link : links) {
if (requestPath.equals(link.getLinkEn()) || 
requestPath.equals(link.getLinkEs())) {
return new 
PageRenderRequestParameters(link.getLogical(), new EmptyEventContext(), false);
}

}

return null;
}

With context is simple to do it. I hope help you.

Regards

Carlos Montero

RE: Hyphens in URL possible?

2016-05-02 Thread Davide Vecchi
The JavaDoc for service interface 
org.apache.tapestry5.services.linktransform.PageRenderLinkTransformer seems to 
suggest it can be used for that. However this is just a guess and a pointer if 
you want to look at it, because I have no previous knowledge or experience with 
that. I'm sure you are going to get more accurate replies to this.

-Original Message-
From: Stephen Nutbrown [mailto:steves...@gmail.com] 
Sent: Monday, May 2, 2016 11:51
To: Tapestry users 
Subject: Hyphens in URL possible?

Hi,

I am working on a tapestry project and someone has asked me to change the URLs 
to include hyphens which they believe will improve SEO.

As per https://support.google.com/webmasters/answer/76329?hl=en, it's 
supposedly good practise to "Consider using punctuation in your URLs. The URL 
*http://www.example.com/green-dress.html
* is much more useful to us than 
*http://www.example.com/greendress.html
*. We recommend that you use hyphens 
(-) instead of underscores (_) in your URLs."

So, let's say I have a page called: GreenDress, which has a GreenDress.java and 
a GreenDress.tml.

Is there any way I can change that to "Green-Dress"? I'm not sure a hyphen is 
even a valid character in a Java class name, so I assume there is another way 
to do it?

Thanks,
Steve

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


Hyphens in URL possible?

2016-05-02 Thread Stephen Nutbrown
Hi,

I am working on a tapestry project and someone has asked me to change the
URLs to include hyphens which they believe will improve SEO.

As per https://support.google.com/webmasters/answer/76329?hl=en, it's
supposedly good practise to "Consider using punctuation in your URLs. The
URL *http://www.example.com/green-dress.html
* is much more useful to us
than *http://www.example.com/greendress.html
*. We recommend that you use
hyphens (-) instead of underscores (_) in your URLs."

So, let's say I have a page called: GreenDress, which has a GreenDress.java
and a GreenDress.tml.

Is there any way I can change that to "Green-Dress"? I'm not sure a hyphen
is even a valid character in a Java class name, so I assume there is
another way to do it?

Thanks,
Steve


Changing Grid.currentPage persistency to flash

2016-05-02 Thread Davide Vecchi
Hi everybody

I see that the instance field that holds the current page number of a grid 
(org.apache.tapestry5.corelib.components.Grid.currentPage) is annotated with 
@Persist .

This has the probably desirable effect that f.ex. if I am on webpage A and it 
has a grid and I browse to its page #2 and then I go to another webpage and 
then I go back to webpage A its grid is still on its page #2 where I had left 
it.

However in my case this is not desirable and I would prefer that the grid page 
number is not remembered across different webpages.

Removing the @Persist annotation of Grid.currentPage instance field altogether 
would cause the impossibility to browse grid pages at all because the grid 
pager does a page reload and this loses the currentPage value, but persisting 
that value just until the next request - to preserve that value during the page 
reload  - seems to work fine: I changed the annotation from

@Persist

to

@Persist(PersistenceConstants.FLASH)

and I'm testing my pages to make sure this works. However I am also wondering 
if in theory changing that persistency to flash might be a bad idea for reasons 
that I don't know and that my tests so far are not showing. Does anyone have 
any opinion about this ?