dataTable displays duplicate record after rowEdit ajax event

UI Components for JSF
Post Reply
russellelbert
Posts: 2
Joined: 21 Aug 2013, 20:52

21 Aug 2013, 21:11

Thank you for your time and the amazing help this board has offered me. This is my first post, so please correct me if I am asking anything inappropriately.

I am using the dataTable component of PrimeFaces 3.4.2 in JSF 2.1 on Apache Tomcat 6.0.14 --- I want to be able to allow the user to edit rows directly in the table.

Following is my code, somewhat edited for brevity:

page:

Code: Select all

<h:form id="platformSpecForm" style="margin:0px 0px 20px 0px">

    <p:dataTable id="platformSpecsTable" editable="true" 
                     value="#{platformView.platformSpecs}" var="pp" rowKey="#{pp.id}" >

        <p:ajax event="rowEdit" listener="#{platformView.onPlatformPropertyEdit}" 
                                       update=":allMessages,@this" />  

            <f:facet name="header" >
                  <h:outputText value="Platform Properties for: #{platformView.platform.title}"/>
            </f:facet> 

            <p:column>
                     <p:rowEditor/>  
            </p:column> 
                        
            <p:column headerText="ID">
                       <h:outputText value="#{pp.id}"/>
             </p:column>

             <p:column  headerText="Type">
                      <p:cellEditor>
                          <f:facet name="output">
                                    <h:outputText value="#{pp.specType.title}"/>
                          </f:facet>
                          <f:facet name="input">
                                    <p:selectOneMenu id="specTypeId" value="#{pp.specTypeId}">
                                        <f:selectItems value="#{platformView.specTypes}" var="st"  
                                                         itemLabel="#{st.title}" itemValue="#{st.id}" />
                                    </p:selectOneMenu>
                                    <h:message for="specTypeId" class="redError" />
                          </f:facet>
                      </p:cellEditor>
             </p:column>

             <p:column headerText="Description">
                      <p:cellEditor>
                          <f:facet name="output">
                                <h:outputText value="#{pp.description}"/>
                          </f:facet>
                          <f:facet name="input">
                                <p:inputTextarea id="description" value="#{pp.description}"  
                                                maxlength="2000" style="width:95%" rows="4" autoResize="false"/>
                                <h:message for="description" class="redError"/>
                          </f:facet>
                      </p:cellEditor>
             </p:column>

                    </p:dataTable>

                </h:form>
the @ViewScoped backing bean method called when a row is edited:

Code: Select all

    public void onPlatformPropertyEdit(RowEditEvent event) { 
        try {
            PlatformSpec ps = (PlatformSpec) event.getObject(); //grab the object edited
            platformSpecService.updatePlatformSpec(ps); //update it in the database
            platformSpecs = platformSpecService.getAllByPlatformId(platform.getId()); //re-fetch the entire list
        } catch (Exception e) {
            HijackError.gotoErrorPage(e);
        }
    }  
Everything looks good initially when displaying the page. However i am coming across a really odd issue when editing rows.

If i click the edit icon, make a change, then click the update icon (checkmark), the database is updated as expected. however the table dosn't display the updated value, but instead duplicates a different row.

example - if i have 5 rows, with the IDs 1, 2, 3, 4, and 5... and I edit row 3. after i click the update icon the table will display something like rows 1, 2, 2, 4, and 5... if i refresh the page manually the appropriate data is displayed in the table.

Hopefully someone can easily see what I am doing wrong. Please let me know if you need more code, or other areas that are meaningful to this question. and thank you for your time!

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

22 Aug 2013, 03:57

russellelbert wrote:Thank you for your time and the amazing help this board has offered me.
does this mean that you have searched this forum, multiple/many times, and found solutions/answers to any/all your questions? since this is your first post/question, I assume the answer is yes. i hope the answer is yes.

now, i will assume the answer is yes, and ask you to continue searching this forum for answers to your questions.

rowedit event update

click the URL above, read all forum topics (and every page of forum topics) in the search results, and look at how people use p:ajax event="rowEdit" update="...". i'm sure that may help you solve this issue (by looking at other people's code). also, you may want to search this forum for:

rowedit ajax viewscoped update

and do as I advised above (read every forum topics on every page of the search results...until you are able to solve the issue). :)
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

russellelbert
Posts: 2
Joined: 21 Aug 2013, 20:52

23 Aug 2013, 18:09

Correct, I have scoured this forum and Stackoverflow for a day and a half before asking, and I appreciate your link to possible solutions. Unfortunately most of the posts listed are not quite the same issue, and the few that are somewhat related do not present a solution.

I have done quite a bit of troubleshooting on this issue, and duplicated the code from the showcase with no success. For the most part I am quite familiar with PrimeFaces, and use it heavily in a dozen internal systems, but have not been able to resolve this particular issue; hence the question finally posted on this forum hoping for assistance. With no solutions found online, I assume others with this issue have not solved it either (as it could be a bug?) - it's possible the Elite releases (currently 3.5.13) could have fixed the issue, unfortunately I do not have that access.

Again, thank you for your time - if I do solve this, or find a workaround I will post it here.

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

23 Aug 2013, 19:00

I don't use rowEdit/cellEditor at all. I use a more traditional JSF approach; datatable == readonly (always, except for when entire datatable == editable). I use multiple row selection on datatable and user can 'edit' ONE row at a time, and EDIT will usually 'render' a separate page allowing enduser to EDIT data.

It seems to be something wrong with the rowKey after update/save is clicked for rowEdit, and rows in the datatable are not updated accordingly. I wonder if you can reload the List<> or Collection<> which is referenced by p:dataTable value="...."; maybe you can reload the datatable from the database via your bean method which is referenced by rowEdit ajax event.

for traditional approach, search google for 'balusc using datatables', and read that entire blog. I think I remember seeing something similar to PrimeFaces cell editor...implemented there in that balusc blog.

yes, post your solution, but I see a lot of rowEdit/cellEditor topics in this forum, and I don't see a lot of responses on those topics, but honestly, most of the time, I don't open those forum topics.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

jimklo
Posts: 5
Joined: 15 Jul 2014, 02:56

15 Oct 2014, 03:28

Did you ever solve this issue and determine it's cause?

Thanks.
PF 4 + JSF 2.2 + Glassfish 4

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

15 Oct 2014, 10:41

jimklo wrote:Did you ever solve this issue and determine it's cause?

Thanks.
Do you seriously think that after 2 years the OP is going to reply?
Please read the forum rules and pay particular attention to resurrecting old/dead threads.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

warriorshadow
Posts: 42
Joined: 12 Sep 2013, 15:34

25 Feb 2016, 19:06

andyba wrote:
jimklo wrote:Did you ever solve this issue and determine it's cause?

Thanks.
Do you seriously think that after 2 years the OP is going to reply?
Please read the forum rules and pay particular attention to resurrecting old/dead threads.
Where can I check if this issue is resolved? I didn't find in any place of the forum, a solution for this issue. may I have to make a issue in primefaces github tracker?
Primefaces 5.2
Apache Tomcat 7.0.34
NetBeans 7.3.1
Linux Ubuntu

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 33 guests