You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "semerau@hotmail.com" <se...@hotmail.com> on 2006/06/10 06:46:51 UTC

conditional and nested ul and li tags

I am trying to set up a page that has comments listed in a big list surrounded by ul tags. Under certains conditions, I want to nest more ul tags. Like this:<ul>    <li>this is post 1</li>    <li>this is post 2</li>    <ul>        <li>this is reply to post 2</li>        <li>this is another reply to post 2</li>        <li>this it yet an additional reply</li>        <ul>            <li>And this is a reply to the one above</li>        </ul>        <li>The last reply to post 2</li>    </ul>    <li>this is post 3</li></ul>However, I run into problem in Tapestry when I try to do something like this:<span jwcid="ifSomething">    </ul></span>Tapestry complains that I am improperly nesting a </ul> tag inside a span. One way I thought of getting arround this was to use an Insert so that the html would be:<span jwcid="ifSomething">    <span jwcid="insertUlTag"/></span>Which sort of worked until I go to the page descriptor and I couldn't figure out how to put "<ul>" in the binding:<component id="insertUlTag" type="Insert">        <binding name="value" value="<ul>"/>           </component>The parser complained and using CDATA didn't help. So I ended up making a getUlOpenTag method on the java file for the page which return "<ul>" so then I had this:<component id="insertUlOpenTag" type="Insert">        <binding name="value" value="ulOpenTag"/>              <binding name="raw" value="true"/>     </component>and that worked.But is there not an easier way? I actually ended up creating a new library that just had open and close HTML tags just for instances like this.Thanks
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

Re: conditional and nested ul and li tags

Posted by Ryan Holmes <ry...@hyperstep.com>.
First, you can't nest UL tags outside of LI tags. I'm sure most browsers 
will render it correctly, but a more strict parser (like the Tapestry 
page parser) will choke on it. Your HTML structure needs to be:

<ul>
    <li>Post 1</li>
    <li>Post 2
       <ul>
          <li>Post 2, Reply A</li>
          <li>Post 2, Reply B
                <ul>
                    <li>Post 2, Reply B, Reply i</li>
                    <li>Post 2, Reply B, Reply ii</li>
                </ul>
          </li>
          <li>Post 2, Reply C</li>
       </ul>
    </li>
   <li>Post 3</li>
</ul>

Second, in page and component specifications, binding values are assumed 
to be OGNL calls unless you specify a prefix (unlike templates, where 
values are assumed to be literal strings unless there is a prefix). So 
there are two ways to fix your Insert component:

<component id="insertUlTag" type="Insert">
	<binding name="value" value="'<ul>'"/>
	<binding name="raw" value="true"/>
</component>

-- or --

<component id="insertUlTag" type="Insert">
	<binding name="value" value="literal:<ul>"/>
	<binding name="raw" value="true"/>
</component>

Note that the "raw" parameter is required to prevent Tapestry from 
escaping the HTML.

Last, you're probably looking for a recursive "DisplayReplies" component 
to walk the tree of replies and created nested UL's and LI's as needed. 
That's a little difficult to do in Tapestry because you can't create 
simple recursive components. In other words, you can't easily render 
(conditionally or otherwise) a component inside of itself without a 
getting a stack overflow exception. You have to use a trick involving 
Block and RenderBlock to get recursive behavior. If you're interested, I 
can post a tiny Tapestry app that demonstrates how to do this. It uses 
"articles" and "comments" rather than posts and replies, but it is a 
stripped down demo with one page and one component demonstrating what I 
think you are trying to do and nothing more (and it uses UL and LI tags).

-Ryan

semerau@hotmail.com wrote:
> I am trying to set up a page that has comments listed in a big list surrounded by ul tags. Under certains conditions, I want to nest more ul tags. Like this:<ul>    <li>this is post 1</li>    <li>this is post 2</li>    <ul>        <li>this is reply to post 2</li>        <li>this is another reply to post 2</li>        <li>this it yet an additional reply</li>        <ul>            <li>And this is a reply to the one above</li>        </ul>        <li>The last reply to post 2</li>    </ul>    <li>this is post 3</li></ul>However, I run into problem in Tapestry when I try to do something like this:<span jwcid="ifSomething">    </ul></span>Tapestry complains that I am improperly nesting a </ul> tag inside a span. One way I thought of getting arround this was to use an Insert so that the html would be:<span jwcid="ifSomething">    <span jwcid="insertUlTag"/></span>Which sort of worked until I go to the page descriptor and I couldn't figure out how to put "<ul>" in the binding:<component id="insertUlTag" type="Insert">        <binding name="value" value="<ul>"/>           </component>The parser complained and using CDATA didn't help. So I ended up making a getUlOpenTag method on the java file for the page which return "<ul>" so then I had this:<component id="insertUlOpenTag" type="Insert">        <binding name="value" value="ulOpenTag"/>              <binding name="raw" value="true"/>     </component>and that worked.But is there not an easier way? I actually ended up creating a new library that just had open and close HTML tags just for instances like this.Thanks
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today it's FREE!
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>   


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