Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate a dynamic table from a java.util.Map
    text
    copied!<p>I'm developing a web application in JSF 2.0. In my application I need a table for viewing presences.</p> <p>I have a <code>Map&lt;Date, List&lt;Presence&gt;&gt;</code> in my 'PresenceService' bean.</p> <p>The Presence object has a Person object (with name and surname) and a boolean present/not present.</p> <p>I'd like to create a table that looks like this:</p> <pre class="lang-none prettyprint-override"><code> monday tuesday wednesday ... Name Person 1 present not present present ... Name Person 2 present present present ... ... ... ... ... ... </code></pre> <p>Which JSF components could I use to create such a table? Or should I not be using a Map for this? I tried creating a table myself with <code>&lt;ui:repeat&gt;</code>'s but failed to do so. As wel the colums as the rows can be dynamic since the user can choose a period and a range of persons.</p> <p><strong>EDIT: solution (see answer Balus C)</strong></p> <p>This works like a charm:</p> <pre><code> &lt;table&gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;ui:repeat value="#{aanwezigheidController.siAanwezigheidService.datums}" var="datumHeader"&gt; &lt;th&gt; &lt;h:outputText value="#{datumHeader}"&gt; &lt;f:convertDateTime pattern="dd/MM/yyyy" /&gt; &lt;/h:outputText&gt; &lt;/th&gt; &lt;/ui:repeat&gt; &lt;/tr&gt; &lt;ui:repeat value="#{aanwezigheidController.siAanwezigheidService.aanwezigheidSiRijen}" var="aanwRij"&gt; &lt;tr&gt; &lt;td&gt;#{aanwRij.persoon.naam} #{aanwRij.persoon.voornaam}&lt;/td&gt; &lt;ui:repeat value="#{aanwezigheidController.siAanwezigheidService.datums}" var="datumCell"&gt; &lt;td&gt; &lt;h:outputText value="aanwezig" rendered="#{aanwRij.aanwezighedenMap[datumCell].aanwezig}" /&gt; &lt;h:outputText value="afwezig" rendered="#{!aanwRij.aanwezighedenMap[datumCell].aanwezig}" /&gt; &lt;/td&gt; &lt;/ui:repeat&gt; &lt;/tr&gt; &lt;/ui:repeat&gt; &lt;/table&gt; </code></pre>
 

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