Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>While it may be actually possible to hack something with <code>h:panelGrid</code>, you probably would have to fiddle with a lot of unnecessary code in your MBs, just for creating and binding components.</p> <p>If you want a finer grained control for your HTML table, what you want to do is probably to use <code>ui:repeat</code>, something like this:</p> <pre><code>&lt;table&gt; &lt;ui:repeat var="elem" value="#{yourMB.yourDataList}"&gt; &lt;tr&gt; &lt;td&gt;#{elem.userid}&lt;/td&gt; &lt;td&gt; &lt;h:outputText value="#{elem.name}" rendered="#{not elem.editable}" /&gt; &lt;h:inputText value="#{elem.name}" rendered="#{elem.editable}" /&gt; &lt;/td&gt; &lt;td&gt; &lt;h:outputText value="#{elem.telephone}" rendered="#{not elem.editable}" /&gt; &lt;h:inputText value="#{elem.telephone}" rendered="#{elem.editable}" /&gt; &lt;/td&gt; &lt;td&gt; &lt;h:commandLink value="Edit" rendered="#{not elem.editable}" action="#{yourMB.editAction(elem)}" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/ui:repeat&gt; &lt;/table&gt; &lt;h:commandButton value="Save Changes" action="#{yourMB.saveAction}" /&gt; </code></pre> <p>For this to work you should have a backing bean looking like this:</p> <pre><code>@ManagedBean @ViewScoped public class YourMB { private List&lt;Elem&gt; dataList; @PostConstruct public void init() { // initialize dataList here } public void editAction(Elem e) { e.setEditable(true); } public void saveAction() { // do your thing here to update in the database, // and then reset the editable property for all items: for (Elem e : dataList) { e.setEditable(false); } } // getters and setters... } </code></pre> <p>Check out <a href="http://www.coreservlets.com/JSF-Tutorial/jsf2/#Looping" rel="nofollow">the tutorials available here</a>, which teaches how to use <code>ui:repeat</code> and also presents other options for looping in JSF.</p>
 

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