Luther,

My practice is a carry-over from T4.  It could use some streamlining.

I have a Menu component class with 

        public String getPageName(){
                return _resources.getPageName();
        }

And then in my Menu.tml, I use the ognl binding available from the
t5components library, and also the ifRole component from the tapestry5-acegi
security library:


<div id="menu">
        <ul id="fmpnav">
                <li class="dummy" ><a href="#" t:type="PageLink"
page="Summary"
        
disabled="ognl:pageName.equals('Summary')">Home</a></li>
                <li class="dummy" ><a href="#">Tools</a>
                <ul>
                                <li class="dummy" ><a href="#"
t:type="ActionLink" t:id="Logout">Logout</a>
                                </li>
                                <li class="dummy" >
                                        <a href="#" t:type="PageLink"
t:page="PasswordChange"
        
disabled="ognl:pageName.equals('PasswordChange')">Password
                                                Change</a>
                                </li>
                        </ul>
                </li>
                <t:security.ifrole role="ROLE_ADMIN">
                <li>
                        Administration<br/>
                        <ul class="submenu">
                                <li>
                                        <a href="#" t:type="PageLink"
t:page="admin/ItemListTypeList"
        
disabled="ognl:pageName.equals('admin/ItemListTypeList')">ItemListTypeList</
a>
                                </li>
                                <li>
                                        <a href="#" t:type="PageLink"
t:page="admin/ItemListTypeEdit"
        
disabled="ognl:pageName.equals('admin/ItemListTypeEdit')">ItemListTypeEdit</
a>
                                </li>
                        </ul>
                </li>
                </t:security.ifrole>
        </ul> 

Jonathan

> -----Original Message-----
> From: Luther Baker [mailto:[EMAIL PROTECTED]
> Sent: Thursday, October 02, 2008 12:51
> To: Tapestry users
> Subject: Re: template dynamics
> 
> Sorry.
> 
> My point was to ask for suggestions. My tapestry development is in
> somewhat
> of a Vacuum so looking for some hints for this end goal. This process is a
> bit point blank... maybe there is a better method to use on the java class
> that is a part of the lifecycle of the component. As mentioned earlier,
> I'm
> going to look into <t:block and see how that works in this case.
> 
> One final question: I've got a fairly standard set of top level menu
> links.
> I am dumping the href and label text into the messages file. At the very
> least, I think I need to put the labels there - but it strikes me that
> there
> may be a better way to reference the hrefs a bit more dynamically.
> 
> Anyone have any thoughts on this? So, in my layout or HtmlShell.tml file I
> do this:
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml"; xmlns:t="
> http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
> ...
>         <div id="header">
>             <ul class="horizRight">
>                 <li><t:condLink currentAnchorHref="${currentAnchorHref}"
> targetAnchorHref="${message:viewNotes-anchorHref}">${message:viewNotes-
> anchorLabel}</t:condLink></li>
>                 <li><t:condLink currentAnchorHref="${currentAnchorHref}"
> targetAnchorHref="${message:addNote-anchorHref}">${message:addNote-
> anchorLabel}</t:condLink></li>
>                 <li><t:condLink currentAnchorHref="${currentAnchorHref}"
> targetAnchorHref="${message:home-anchorHref}">${message:home-
> anchorLabel}</t:condLink></li>
>             </ul>
> ...
> </html>
> 
> I wonder if there is a better way to find the targetAnchorHref. As noted
> previously, this approach forces my basic pages to tell me who they are
> when
> they include the layout component. Notice the "currentAnchorHref" passed
> in
> here..
> 
> <t:htmlShell currentAnchorHref="${message:self-anchorHref}"
> currentHeadTitle="${message:self-headTitle}"
> currentBodyTitle="${message:self-bodyTitle}" xmlns:t="
> http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";
> xml:space="preserve">
> 
> 
> Again, any thoughts or suggestions are much appreciated.
> 
> -Luther
> 
> 
> 
> 
> On Thu, Oct 2, 2008 at 11:35 AM, Luther Baker <[EMAIL PROTECTED]>
> wrote:
> 
> > I wrote a small custom menu component that includes or doesn't include
> an
> > anchor href based on the href of the current page.
> >
> > I wonder if the block approach suggested here would be cleaner? I use
> the
> > following idiom:
> >
> > <t:if test="different" xmlns:t="
> > http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
> >         <t:body/>
> >     <t:parameter name="else">
> >         <t:pageLink page="${targetAnchorHref}"><t:body/></t:pageLink>
> >     </t:parameter>
> > </t:if>
> >
> > to render this pseudo-dynamically (notice that 'about' has no anchor
> tag):
> >
> > <ul>
> >   <li><a href="home">home</a></li>
> >   <li><a href="contact">contact</a></li>
> > *  <li>about</li>
> > *</ul>
> >
> >
> > The JAVA:
> >
> > public class CondLink
> > {
> >     @Property
> >     @Parameter(required=true, defaultPrefix="literal")
> >     private String currentAnchorHref;
> >
> >     @Property
> >     @Parameter(required=true, defaultPrefix="literal")
> >     private String targetAnchorHref;
> >
> >     public boolean isDifferent()
> >     {
> >         return this.currentAnchorHref.equals(this.targetAnchorHref);
> >     }
> > }
> >
> >
> > The ConditionalLink.tml:
> >
> > <t:if test="different" xmlns:t="
> > http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
> >         <t:body/>
> >     <t:parameter name="else">
> >         <t:pageLink page="${targetAnchorHref}"><t:body/></t:pageLink>
> >     </t:parameter>
> > </t:if>
> >
> >
> > The LAYOUT - HtmlShell.tml:
> >
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
> > http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> > <html xmlns="http://www.w3.org/1999/xhtml"; xmlns:t="
> > http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
> > ...
> >         <div id="header">
> >             <ul class="horizRight">
> >                 <li><t:condLink currentAnchorHref="${currentAnchorHref}"
> > targetAnchorHref="${message:viewNotes-anchorHref}">${message:viewNotes-
> anchorLabel}</t:condLink></li>
> >                 <li><t:condLink currentAnchorHref="${currentAnchorHref}"
> > targetAnchorHref="${message:addNote-anchorHref}">${message:addNote-
> anchorLabel}</t:condLink></li>
> >                 <li><t:condLink currentAnchorHref="${currentAnchorHref}"
> > targetAnchorHref="${message:home-anchorHref}">${message:home-
> anchorLabel}</t:condLink></li>
> >             </ul>
> > ...
> > </html>
> >
> >
> > The PAGE: index.tml
> >
> > <t:htmlShell currentAnchorHref="${message:self-anchorHref}"
> > currentHeadTitle="${message:self-headTitle}"
> > currentBodyTitle="${message:self-bodyTitle}" xmlns:t="
> > http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";
> > xml:space="preserve">
> >     <ul class="horizLeft">
> >        <li><t:pageLink
> > page="${message:add-anchorHref}">${message:add-
> anchorLabel}</t:pageLink></li>
> >
> >        <li><t:pageLink
> > page="${message:view-anchorHref}">${message:view-
> anchorLabel}</t:pageLink></li>
> >     </ul>
> > </t:htmlShell>
> >
> >
> >
> > On Thu, Oct 2, 2008 at 9:19 AM, Ulrich Stärk <[EMAIL PROTECTED]> wrote:
> >
> >> That's a really nice solution. Have to keep that in mind.
> >>
> >> Uli
> >>
> >> Am Do, 2.10.2008, 15:49, schrieb Filip S. Adamsen:
> >> > Hi,
> >> >
> >> > Define Blocks containing the different states you need and use a
> >> > Delegate to render the block you need based on an expression. This
> way
> >> > you can do the whole if-then-else/switch stuff in your page class.
> >> >
> >> > Template:
> >> >
> >> >    <t:block t:name="block1">...</t:block>
> >> >    <t:block t:name="block2">...</t:block>
> >> >
> >> >    <t:delegate t:to="activeblock">
> >> >
> >> > Class:
> >> >
> >> >    @Inject
> >> >    private ComponentResources resources;
> >> >
> >> >    public Block getActiveBlock() {
> >> >      String blockId = ...;
> >> >      return resources.getBlock(blockId);
> >> >    }
> >> >
> >> > It's also possible to have the blocks on another page, in that case
> you
> >> > can get the page through ComponentSource#getPage, get its
> >> > ComponentResources, and go from there.
> >> >
> >> > http://tapestry.apache.org/tapestry5/guide/templates.html (see
> <block>)
> >> >
> >>
> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/Block.ht
> ml
> >> >
> >> http://tapestry.apache.org/tapestry5/tapestry-
> core/ref/org/apache/tapestry5/corelib/components/Delegate.html
> >> >
> >>
> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/Componen
> tResourcesCommon.html#getBlock(java.lang.String)<http://tapestry.apache.or
> g/tapestry5/apidocs/org/apache/tapestry5/ComponentResourcesCommon.html#get
> Block%28java.lang.String%29>
> >> >
> >>
> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/services
> /ComponentSource.html#getPage(java.lang.Class)<http://tapestry.apache.org/
> tapestry5/apidocs/org/apache/tapestry5/services/ComponentSource.html#getPa
> ge%28java.lang.Class%29>
> >> >
> >> > -Filip
> >> >
> >> > On 2008-10-02 14:39, János Jarecsni wrote:
> >> >> Hi Uli,
> >> >>
> >> >> thanks, I did not know about these. However, what if I have to
> switch
> >> >> between more states? If seems to be awkward in that case (if
> embedding
> >> >> is
> >> >> possible at all).
> >> >>
> >> >> Thanks
> >> >> Janos
> >> >>
> >> >> 2008/10/1 Ulrich Stärk <[EMAIL PROTECTED]>
> >> >>
> >> >>> Have a look at the If
> >> >>> (
> >> >>>
> >> http://tapestry.apache.org/tapestry5/tapestry-
> core/ref/org/apache/tapestry5/corelib/components/If.html
> >> >>> )
> >> >>> and Zone
> >> >>> (
> >> >>>
> >> http://tapestry.apache.org/tapestry5/tapestry-
> core/ref/org/apache/tapestry5/corelib/components/Zone.html
> >> >>> )
> >> >>> components.
> >> >>>
> >> >>> Uli
> >> >>>
> >> >>> Am Mi, 1.10.2008, 17:06, schrieb János Jarecsni:
> >> >>>> Hi guys,
> >> >>>>
> >> >>>> is there a way to change the template (piece of the template)
> which
> >> >>>> gets
> >> >>>> generated, depending on state? Here is what I mean:
> >> >>>> Given a component C, its C.tml looks like the following:
> >> >>>>
> >> >>>> <html>blabla...
> >> >>>>
> >> >>>> //if (loggedIn)
> >> >>>> Logged in
> >> >>>> //else
> >> >>>> Not Logged in
> >> >>>>
> >> >>>> </html>
> >> >>>>
> >> >>>> Of course I know this concrete problem can be solved using
> expansion.
> >> >>>> But
> >> >>>> I'm now after replacing large chunks of the template depending on
> >> >>>> state.
> >> >>>> It
> >> >>>> is easy to do so in a JSP page for example.
> >> >>>>
> >> >>>> Thanks in advance,
> >> >>>> janos
> >> >>>>
> >> >>>
> >> >>>
> >> >>> -------------------------------------------------------------------
> --
> >> >>> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> >>> For additional commands, e-mail: [EMAIL PROTECTED]
> >> >>>
> >> >>>
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> > For additional commands, e-mail: [EMAIL PROTECTED]
> >> >
> >> >
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to