[SOLVED]DataTable Does not update

UI Components for JSF
Post Reply
univac
Posts: 14
Joined: 23 Mar 2010, 18:55

21 Sep 2010, 00:42

Hello!

I'm trying to make a datatable; each row has a command button to delete it.
When you press the button, the row gets deleted, but the table DOES NOT
update.

But, if you put a buton outside the <p:dataTable> structure, the ajax
updating works fine.

I wrote this simple application to isolate the problem:

Facelet:

Code: Select all

    <h:body>
    <h:form>
        <p:dataTable id="table"
                            value="#{animalBean.animalList}" 
                            var="currentAnimal" 
                            rowIndexVar="currentIndex">
            <f:facet name="header">Animals</f:facet>
            <p:column>
                <f:facet name="header">Animal index</f:facet>
                <h:outputText value="#{currentIndex}"/>
            </p:column>
            <p:column>
                <f:facet name="header">Animal name</f:facet>
                <h:outputText value="#{currentAnimal}"/>
            </p:column>
            <p:column>
                <f:facet name="header">Remove buttons</f:facet>
                <p:commandButton value="Remove" 
                                             update="table" 
                                             actionListener="#{animalBean.deleteAnimal}">
                    <f:param name="deleteIndex" value="#{currentIndex}"/>
                </p:commandButton>
            </p:column>
            <f:facet name="footer"/>
        </p:dataTable>
        <br/>
        <p:commandButton value="Remove First Animal" 
                                     update="table"
                                     actionListener="#{animalBean.deleteAnimal}">
            <f:param name="deleteIndex" value="0"/>
        </p:commandButton>
    </h:form>
    </h:body>
Again, when you press the outside button, it deletes and updates, but when
you press the row's delete button, it deletes but not updates.

What am I missing?

Thank you very much.

Estéban.

JEE5, JSF2.0, GlassFish3, PrimeFaces 2.2.
Last edited by univac on 21 Sep 2010, 18:46, edited 1 time in total.

callahan
Posts: 768
Joined: 27 May 2010, 22:52

21 Sep 2010, 10:10

Hi,

I'd imagine that you're have the issue discussed here http://primefaces.prime.com.tr/forum/vi ... =10#p16178.

User avatar
michiel
Posts: 240
Joined: 07 Jun 2010, 09:12
Location: Belgium

21 Sep 2010, 10:19

you can work around this by changing to update="@form":

Code: Select all

<p:commandButton value="Remove" update="@form" actionListener="#{animalBean.deleteAnimal}">
    <f:param name="deleteIndex" value="#{currentIndex}"/>
</p:commandButton>
JSF-2.0, mojarra-2.0.2-FCS and PrimeFaces-2.1 on GlassFish v3.0.1 (build 22)

univac
Posts: 14
Joined: 23 Mar 2010, 18:55

21 Sep 2010, 19:00

Hello,

Im new to JSF, this is an issue that is not very well documented and can
be a little frustrating for the begginer.

Anyway, it seems like each <h:form>is an independent 'id' context,
so you can only ajax-update components inside the same form.

To update a component in a different form, you just have to give
an id to the target form, and then call the update referencing
that id:

<h:form id="f1">
<h:outputText id="text" value=#{Bean.value}/>
</h:form>

<h:form>
<p:comandButton value="Click to update"
actionListener="#{Bean.updateValue}"
update="f1:text"/>
</h:form>


if you use something like update="@form" it will work, but you will
update the entire form and i'ts not the ajax philosophy.

I think a good practice would be:

1. Give all forms an id.
2. update all components referencing its form,
even if they are in the same form.

This has solved all my problems, I am using a very complex layout,
so I need to update components everywhere.

Thank you very much.

Estéban.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 61 guests