Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to draw diamond using tapestry component t:loop
    primarykey
    data
    text
    <p>For my homework for Tapestry, I have to show a diamond on table from array of strings. Here's what I have so far:</p> <p>code Index.java</p> <pre><code> public class Index { @Property private Integer number; @Property private String [] table; public Index() { number = 9; int temp = 0; String tmp = "-"; table = new String[number * number]; if(singleCell == null) singleCell=""; for (int i = 0; i &lt; number; i++) { for (int j = 0; j &lt; number; j++) { table[temp] = tmp; temp++; } } } @OnEvent(component="diamond") Object onDiamondLink() { String swapValue = "*"; int sum = number / 2 ; int x1 = number-1; int sumY = number / 2; int y1 = number+1; int temp = x1 + sumY; for (int i = 0; i &lt; table.length; i++) { table[i] = "-"; } for (int i = 0; i &lt; table.length; i++) { if( i == sum) { table[i] = swapValue; sum = sum + x1; } if ( i == sumY ) { table[i] = swapValue; sumY = sumY + y1; } } System.out.println("link diamond is activate"); return null; } public boolean isStartRow(){ return (myIndex%9 ==0); } public boolean isEndRow(){ return (myIndex%9 == 8); } public String getStartTR(){ return "&lt;tr &gt;"; } public String getEndTR(){ return "&lt;/tr&gt;"; } </code></pre> <p>code of index.tml:</p> <pre><code>&lt;t:actionlink t:id="diamond" &gt;Diamond table&lt;/t:actionlink&gt; &lt;br/&gt; &lt;h1&gt;Result:&lt;/h1&gt; &lt;table border="1" &gt; &lt;t:loop t:source="table" t:value="singleCell" index="MyIndex"&gt; &lt;t:if test="startRow"&gt; &lt;t:outputraw value="startTR"/&gt; &lt;/t:if&gt; &lt;td width="20px"&gt; ${singleCell} &lt;/td&gt; &lt;t:if test="endRow"&gt; &lt;t:outputraw value="endTR"/&gt; &lt;/t:if&gt; &lt;/t:loop&gt; &lt;/table&gt; </code></pre> <p>This code generates this output:</p> <pre><code>- - - - * - - - - - - - * - * - - - - - * - - - * - - - * - - - - - * - * - - - - - - - * - - - - - - - * - * - - - - - * - - - * - - - * - - - - - * - * - - - - </code></pre> <p>The correct output I need is this:</p> <pre><code>- - - - * - - - - - - - * - * - - - - - * - - - * - - - * - - - - - * - * - - - - - - - * - * - - - - - * - - - * - - - * - - - - - * - * - - - - - - - * - - - - </code></pre> <p>Any ideas will be great help.</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.
 

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