Note that there are some explanatory texts on larger screens.

plurals
  1. POLooping a certain number of times in tapestry template
    primarykey
    data
    text
    <p>In a Tapestry component template, is there a simple way to render some markup X times, where X is a parameter of the component?</p> <p>All I can find in the Tapestry docs is the Loop component:</p> <pre class="lang-html prettyprint-override"><code>&lt;table class="navigation" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"&gt; &lt;tr&gt; &lt;t:loop source="pageNames" value="pageName"&gt; &lt;td class="${tabClass}"&gt; &lt;t:pagelink page="pageName"&gt;${pageName}&lt;/t:pagelink&gt; &lt;/td&gt; &lt;/t:loop&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>But this is overkill if I just want to render something X times, without needing to pass any parameters. For this usecase I'd really expect something like (pseudo-code):</p> <pre class="lang-html prettyprint-override"><code>&lt;table class="navigation" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"&gt; &lt;tr&gt; &lt;t:loop times="${x}"&gt; &lt;!-- same markup every time --&gt; &lt;/t:loop&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>But nothing like this seems to exist - or does it?</p> <p>For now my workaround is to provide a stub implementation of List which gives size X, and use that as my Loop source:</p> <p>Class:</p> <pre class="lang-java prettyprint-override"><code>private int x; public List&lt;Object&gt; getX() { return new AbstractList&lt;Object&gt;() { public Object get(int arg0) { return null; } public int size() { return x; } }; } </code></pre> <p>Template:</p> <pre class="lang-html prettyprint-override"><code>&lt;t:loop source="x"&gt; &lt;!-- same markup each time --&gt; &lt;/t:loop&gt; </code></pre> <p>But this is very ugly - surely there's a nicer way to do something so straightforward?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload