You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Martin Dietze <di...@fh-wedel.de> on 2007/06/01 12:54:57 UTC

T5: How to generate page links from Java code?

Hi,

 I'm trying to create a component for a navigation element
which contains page links for all of my pages but renders the
currently loaded page differently (i.e. not a href, different
font etc.).

It seems to me like the best way to do this is have my
component's java code write the lines containing the titles and
the underlying links.

Unfortunately I have not been able to find any example how to
do this, in all examples I found the links were created in the
html template rather than the java code.

Can anyone here help me out?

Cheers,

Martin

-- 
----------- / http://herbert.the-little-red-haired-girl.org / -------------
=+= 
"We waste time looking for the perfect lover, instead of creating the
perfect love."  -- Tom Robbins, _Still Life With Woodpecker_

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


Re: T5: How to generate page links from Java code?

Posted by Martin Grotzke <ma...@javakaffee.de>.
On Mon, 2007-06-04 at 17:21 +0700, Ivan Dubrov wrote:
> Nick Westgate wrote:
> > Hi Martin.
> >
> > A typical way to do this in previous Tapestry versions is to have
> > some simple logic functions in your component class to provide a
> > boolean result ("this link is to the current page") which is used
> > for each link's disabled parameter, and to select a string supplied
> > to an informal CSS "style" parameter on each link.
> >
> > T5 would be the same, except that the core PageLink component needs
> > a few tweaks to be fit for your task - so roll your own from that -
> > and you will have to create an equivalent of the old getPageName().
> >   
> 
> BTW, you can use resolver.resolvePageClassNameToPageName(pageClassName)
> to get page name for given page class name, where resolver is
> org.apache.tapestry.services.ComponentClassResolver. Current page class
> name could be retrieved as
> resources.getPage().getComponentResources().getComponentModel().getComponentClassName(),
> where resources is org.apache.tapestry.ComponentResources injected in
> component. That's how my menu is working.

Great, thx for this info!

Cheers,
Martin



Re: T5: How to generate page links from Java code?

Posted by Ivan Dubrov <wf...@gmail.com>.
Nick Westgate wrote:
> Hi Martin.
>
> A typical way to do this in previous Tapestry versions is to have
> some simple logic functions in your component class to provide a
> boolean result ("this link is to the current page") which is used
> for each link's disabled parameter, and to select a string supplied
> to an informal CSS "style" parameter on each link.
>
> T5 would be the same, except that the core PageLink component needs
> a few tweaks to be fit for your task - so roll your own from that -
> and you will have to create an equivalent of the old getPageName().
>   

BTW, you can use resolver.resolvePageClassNameToPageName(pageClassName)
to get page name for given page class name, where resolver is
org.apache.tapestry.services.ComponentClassResolver. Current page class
name could be retrieved as
resources.getPage().getComponentResources().getComponentModel().getComponentClassName(),
where resources is org.apache.tapestry.ComponentResources injected in
component. That's how my menu is working.

-- 
WBR,
Ivan S. Dubrov



Re: T5: How to generate page links from Java code?

Posted by Nick Westgate <ni...@key-planning.co.jp>.
Hi Martin.

A typical way to do this in previous Tapestry versions is to have
some simple logic functions in your component class to provide a
boolean result ("this link is to the current page") which is used
for each link's disabled parameter, and to select a string supplied
to an informal CSS "style" parameter on each link.

T5 would be the same, except that the core PageLink component needs
a few tweaks to be fit for your task - so roll your own from that -
and you will have to create an equivalent of the old getPageName().

In general, use HTML templating whenever practical, as this is the
natural format in which to express HTML structure. Then leave the
fine-tuning of the runtime HTML to existing or home-grown components.

Cheers,
Nick.


Martin Grotzke wrote:
> On Fri, 2007-06-01 at 08:48 -0700, Howard Lewis Ship wrote:
>> You have to inject your ComponentResources.
>>
>> There are methods for generating page render links and component action
>> links as part of the ComponentResources interface.
> Great!
> 
> What's then the intended way of rendering the component? Should we
> directly use the MarkupWriter with .element("a" ... etc, or is it
> also possible to let the component render itself?
> 
> If we create a page link in the template (t:pagelink), there might get
> attributes rendered that are not explicitely specified. Now it would be
> nice to get exactly the same markup, even if the component is created in
> java code. Is this somehow possible, and is it intended to be used like
> this?
> 
> Cheers,
> Martin
> 
> 
>> On 6/1/07, Martin Dietze <di...@fh-wedel.de> wrote:
>>> Hi,
>>>
>>> I'm trying to create a component for a navigation element
>>> which contains page links for all of my pages but renders the
>>> currently loaded page differently (i.e. not a href, different
>>> font etc.).
>>>
>>> It seems to me like the best way to do this is have my
>>> component's java code write the lines containing the titles and
>>> the underlying links.
>>>
>>> Unfortunately I have not been able to find any example how to
>>> do this, in all examples I found the links were created in the
>>> html template rather than the java code.
>>>
>>> Can anyone here help me out?
>>>
>>> Cheers,
>>>
>>> Martin
>>>
>>> --
>>> ----------- / http://herbert.the-little-red-haired-girl.org /
>>> -------------
>>> =+=
>>> "We waste time looking for the perfect lover, instead of creating the
>>> perfect love."  -- Tom Robbins, _Still Life With Woodpecker_
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>

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


Re: T5: How to generate page links from Java code?

Posted by Martin Grotzke <ma...@javakaffee.de>.
On Fri, 2007-06-01 at 08:48 -0700, Howard Lewis Ship wrote:
> You have to inject your ComponentResources.
> 
> There are methods for generating page render links and component action
> links as part of the ComponentResources interface.
Great!

What's then the intended way of rendering the component? Should we
directly use the MarkupWriter with .element("a" ... etc, or is it
also possible to let the component render itself?

If we create a page link in the template (t:pagelink), there might get
attributes rendered that are not explicitely specified. Now it would be
nice to get exactly the same markup, even if the component is created in
java code. Is this somehow possible, and is it intended to be used like
this?

Cheers,
Martin


> 
> On 6/1/07, Martin Dietze <di...@fh-wedel.de> wrote:
> >
> > Hi,
> >
> > I'm trying to create a component for a navigation element
> > which contains page links for all of my pages but renders the
> > currently loaded page differently (i.e. not a href, different
> > font etc.).
> >
> > It seems to me like the best way to do this is have my
> > component's java code write the lines containing the titles and
> > the underlying links.
> >
> > Unfortunately I have not been able to find any example how to
> > do this, in all examples I found the links were created in the
> > html template rather than the java code.
> >
> > Can anyone here help me out?
> >
> > Cheers,
> >
> > Martin
> >
> > --
> > ----------- / http://herbert.the-little-red-haired-girl.org /
> > -------------
> > =+=
> > "We waste time looking for the perfect lover, instead of creating the
> > perfect love."  -- Tom Robbins, _Still Life With Woodpecker_
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
> 
> 
-- 
Martin Grotzke
http://www.javakaffee.de/blog/

Re: T5: How to generate page links from Java code?

Posted by Howard Lewis Ship <hl...@gmail.com>.
You have to inject your ComponentResources.

There are methods for generating page render links and component action
links as part of the ComponentResources interface.

On 6/1/07, Martin Dietze <di...@fh-wedel.de> wrote:
>
> Hi,
>
> I'm trying to create a component for a navigation element
> which contains page links for all of my pages but renders the
> currently loaded page differently (i.e. not a href, different
> font etc.).
>
> It seems to me like the best way to do this is have my
> component's java code write the lines containing the titles and
> the underlying links.
>
> Unfortunately I have not been able to find any example how to
> do this, in all examples I found the links were created in the
> html template rather than the java code.
>
> Can anyone here help me out?
>
> Cheers,
>
> Martin
>
> --
> ----------- / http://herbert.the-little-red-haired-girl.org /
> -------------
> =+=
> "We waste time looking for the perfect lover, instead of creating the
> perfect love."  -- Tom Robbins, _Still Life With Woodpecker_
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com