Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic dataTable form deletes its array when ajax is used
    primarykey
    data
    text
    <p>I have a dynamic dataTable that adds and removes objects. This works fine when I don't use ajax. However, when I use ajax, a problem occurs. Adding values initially is fine. However, when I start deleting objects, when I delete the last object, the items list gets deleted as well and becomes null. I am using jsf 2.2 with primefaces. I'm not sure what's causing this problem. My code is as follows.</p> <p>item.xhtml </p> <pre class="lang-html prettyprint-override"><code>&lt;h:panelGroup id="list"&gt; &lt;h:dataTable value="#{item.items}" var="object"&gt; &lt;h:column&gt; &lt;!-- Figure out what these facets are or delete them --&gt; &lt;f:facet name="keys"&gt;Keys&lt;/f:facet&gt; &lt;p:inputText value="#{object.x}" /&gt; &lt;/h:column&gt; &lt;h:column headerText="Values"&gt; &lt;f:facet name="values"&gt;Values&lt;/f:facet&gt; &lt;p:inputText value="#{object.y}" /&gt; &lt;/h:column&gt; &lt;h:column&gt; &lt;h:commandLink value="Delete" action="#{user.removeObject(object)}"&gt; &lt;f:ajax execute="@form" render="@form" /&gt; &lt;/h:commandLink&gt; &lt;/h:column&gt; &lt;/h:dataTable&gt; &lt;h:commandButton value="add" action="#{user.addObject}"&gt; &lt;f:ajax execute="@form" render="@form" /&gt; &lt;/h:commandButton&gt; &lt;/h:panelGroup&gt; </code></pre> <p>item.java</p> <pre><code>@ManagedBean @ViewScoped public class Item implements Serializable{ public void addObject(){ Pair&lt;String,String&gt; tempPair = new Pair&lt;String,String&gt;("",""); items.add(tempPair); return; } public void removeObject(Pair&lt;String,String&gt; i){ items.remove(i); return; } } </code></pre> <p><strong>UPDATE 1</strong></p> <p>I tried using jsf 2.1 instead, changing my viewAction to preRenderView, and my code works fine.</p>
    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.
 

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