You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Filip S. Adamsen" <fs...@fsadev.com> on 2009/04/01 02:51:23 UTC

Re: t5: create a page link inside a service

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Did my e-mail from almost 15 hours ago not get through to everyone on
the list? :P

To quote myself, "Inject the ComponentSource service, get a page from
it, then get its ComponentResources."

I've got a dedicated service for this, it gets the ComponentResources of
the page you want to link to from the ComponentSource, which has the
added benefit of ensuring that you're linking to a valid page.

Here's the relevant code (for 5.0.18):

  private final ComponentClassResolver componentClassResolver;
  private final ComponentSource componentSource;

  public RedirectServiceImpl(ComponentClassResolver
componentClassResolver, ComponentSource componentSource) {
    this.componentClassResolver = componentClassResolver;
    this.componentSource = componentSource;
  }

  public Link createPageLink(Class<?> pageClass, boolean override,
Object... context) {
    String pageName =
componentClassResolver.resolvePageClassNameToPageName(pageClass.getCanonicalName());
    return
componentSource.getPage(pageName).getComponentResources().createPageLink(pageName,
override, context);
  }

You can, of course, do the same for events etc.

/Filip

On 2009-03-31 23:21, Angelo Chen wrote:
> Thanks, but that works for 5.1.x, not for 5.0.18. I'm eagerly expecting the
> release of 5.1.x stable version.
> 
> 
> Howard Lewis Ship wrote:
>> http://tapestry.formos.com/nightly/tapestry5/faq/general.html#create-page-link-from-service
>>
>> On Tue, Mar 31, 2009 at 2:54 AM, Angelo Chen <an...@yahoo.com.hk>
>> wrote:
>>> Hi,
>>>
>>> I'd like to createPageLink inside a services, but ComponentResource can't
>>> be
>>> injected into a service, any other way around? Thanks,
>>>
>>> Angelo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQEcBAEBAgAGBQJJ0rqJAAoJEEfiH7PpjaMnKqYIAKoto5n15bm73SjdEKYewlZZ
F8sgeoHyj1mAIP8xOLH0d5g9PVffYMlMWTWPyJ+JnDS06dy86/mfgDXOEvBaVuBG
8HHtEiVSwTaNZeE8Z2GOljSH4pMYH2KXsOkWwiI/r7mQWD0IDznNEpDkNx250x2q
fkpRGtFWqAchdEj7yRNIGBt9QjgSCstjrXjIJ24IXD+xleHRL3vdJ+4ua2K46/Cc
sykyzmr5eZd53eszXtw3kl6occq2Gg5SPGpBOh2WzG3++KjDu3ncohe0bT312BdW
frMC8hqv+DTQOWauvVC8PQempEglao13Dd97AgnRtrfffw0lPFRvL8iS9jqNCEA=
=BxpZ
-----END PGP SIGNATURE-----

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