Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is possible to do everything you want.</p> <hr> <p>You can build something close to what you want using existing controls. A good way to get the most out of JSF is to tailor the model for the view. For example, this view displays edit options that allow you to add values to a data table.</p> <pre><code>&lt;f:view&gt; &lt;h:form&gt; &lt;h:dataTable value="#{people.list}" var="row"&gt; &lt;h:column&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="#" /&gt; &lt;/f:facet&gt; &lt;h:selectBooleanCheckbox value="#{row.selected}" /&gt; &lt;/h:column&gt; &lt;h:column&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="First Name" /&gt; &lt;/f:facet&gt; &lt;h:inputText value="#{row.firstname}" /&gt; &lt;/h:column&gt; &lt;h:column&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="Last Name" /&gt; &lt;/f:facet&gt; &lt;h:inputText value="#{row.lastname}" /&gt; &lt;/h:column&gt; &lt;f:facet name="footer"&gt; &lt;h:panelGroup&gt; &lt;h:commandButton value="Add Row" action="#{people.addPerson}" /&gt; &lt;h:commandButton value="Delete Selected" action="#{people.deleteSelected}" /&gt; &lt;h:commandButton value="Finish" action="#{people.finish}" /&gt; &lt;/h:panelGroup&gt; &lt;/f:facet&gt; &lt;/h:dataTable&gt; &lt;/h:form&gt; &lt;/f:view&gt; </code></pre> <p>People bean:</p> <pre><code>public class People implements Serializable { private static final long serialVersionUID = 1L; private List&lt;Person&gt; people = new ArrayList&lt;Person&gt;(); public People() { // initialise with one entry people.add(new Person()); } public List&lt;Person&gt; getList() { return people; } public String addPerson() { people.add(new Person()); return null; } public String deleteSelected() { Iterator&lt;Person&gt; entries = people.iterator(); while (entries.hasNext()) { Person person = entries.next(); if (person.isSelected()) { entries.remove(); } } return null; } public String finish() { System.out.println(people); return "someNavigationRule"; } } </code></pre> <p>Person bean:</p> <pre><code>public class Person implements Serializable { private static final long serialVersionUID = 1L; private String firstname; private String lastname; private transient boolean selected = false; public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } public boolean isSelected() { return selected; } public void setSelected(boolean selected) { this.selected = selected; } } </code></pre> <p>faces-config.xml:</p> <pre><code>&lt;managed-bean&gt; &lt;managed-bean-name&gt;people&lt;/managed-bean-name&gt; &lt;managed-bean-class&gt;addmultiple.People&lt;/managed-bean-class&gt; &lt;managed-bean-scope&gt;session&lt;/managed-bean-scope&gt; &lt;/managed-bean&gt; </code></pre> <p>This approach is quite flexible and with some CSS, can look quite good. With a few changes to the view and model, you can have only the last row editable, for example.</p> <hr> <p>If the resultant experience isn't rich enough or if you need something you can reuse, you can create a custom control. It is difficult to get into the specifics without knowing exactly what you want, but you probably would need:</p> <ol> <li>A new <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/render/Renderer.html" rel="noreferrer">Renderer</a> for emitting HTML and decoding form requests.</li> <li>(Maybe) a new <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/component/UIComponent.html" rel="noreferrer">component</a>, probably extending <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/component/UIData.html" rel="noreferrer">UIData</a>, and a <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/component/html/HtmlDataTable.html" rel="noreferrer">concrete form</a> for exposing renderkit-specific (e.g. HTML) attributes.</li> <li>A new JSP <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/webapp/UIComponentELTag.html" rel="noreferrer">tag class</a> for allowing the control to be used in JSPs.</li> <li>Definitions for all of the above in a <em>faces-config.xml</em> (see <a href="http://java.sun.com/javaee/javaserverfaces/download.html" rel="noreferrer">spec</a>).</li> </ol>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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