Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:16:05+00:00 2026-06-17T13:16:05+00:00

I want make CRUD PrimeFaces dataTable with add, filter, edit, delete, pagination features. I

  • 0

I want make CRUD PrimeFaces dataTable with add, filter, edit, delete, pagination features.
I am trying to ‘Add’ a new record in a dialogue (i.e. modal pop-up window) using PrimeFaces 3.4.2 dataTable, JSF 2.1.

All other operations are working good but the dataTable is not updating correctly after an add operation.
It is updated correctly after the 1st add operation.
After that I add 2nd row the dataTable is updated but the row which was added first is replaced with the row which was added 2nd time.
After that I add a 3rd row, the 1st row has got replaced with the 3rd row.
The database tables are getting updated perfect in all the cases.

Code snippet from jsf and managed bean :

JSF code:

<h:body>
<h:form id="form1">

            <h:messages id="messages1"/>
            <br/>

            <p:commandButton id="Addbtn" value="Add" oncomplete="AddDialog.show()" update=":addform"/>                
            <br/>

            <p:dataTable id="dtusers" value="#{userdataController.retrieveData()}" var="item" 
                         rows="8" paginator="true" emptyMessage="No Records Found" 
                         paginatorAlwaysVisible="false">

                <p:column style="width:150px" filterMatchMode="contains" filterBy ="#{item.id}">
                    <f:facet name="header"> Id </f:facet>
                    <h:outputText value="#{item.id}"/>
                </p:column>

                <p:column style="width:150px" filterMatchMode="contains" filterBy="#{item.name}">
                    <f:facet name="header"> Name </f:facet>
                    <h:outputText value="#{item.name}"/>
                </p:column>     

                <p:column style="width:150px">  
                    <p:commandButton id="editButton" update=":editform" oncomplete="EditDialog.show()" value="Edit">
                        <f:setPropertyActionListener value="#{item}" target="#{userdataController.selectedUser}"/>
                    </p:commandButton>                       
                </p:column>

                <p:column style="width:150px">  
                    <p:commandButton id="deleteButton" update=":deleteform" oncomplete="UserDialog.show()" value="Delete">
                        <f:setPropertyActionListener value="#{item}" target="#{userdataController.selectedUser}"/>
                    </p:commandButton>    
                </p:column>                 

            </p:dataTable>
        </h:form>   

 <p:dialog header="Add User Data" resizable="false" id="AddDialog" widgetVar="AddDialog" modal="true" showEffect="fade" hideEffect="fade" position="center" dynamic="true">
            <h:form id="addform">
                <p:outputPanel id="AddDisplay">

                    <p:panelGrid columns="2" >

                        <f:facet name="header">
                            Add Userdata
                        </f:facet>

                        <h:outputLabel for="Id" value="Enter Id:"/>
                        <p:inputText id="Id" value="#{userdataController.selected.id}" />

                        <h:outputLabel for="Name" value="Enter Name:"/>
                        <p:inputText id="Name" value="#{userdataController.selected.name}"/>

                        <p:commandButton  actionListener="#{userdataController.create}" update=":form1:dtusers :form1:messages1" value="Save" oncomplete="AddDialog.hide()" style="margin:0"/>                 

                    </p:panelGrid>
                </p:outputPanel>
            </h:form>
        </p:dialog> 
 </h:body>

Manaed Bean code snippet:

@ManagedBean(name = "userdataController")
    @SessionScoped
    public class UserdataController implements Serializable {

    private Userdata current;
    private DataModel items = null;
    @EJB
    private PrimeFacesDb.session.UserdataFacade ejbFacade;
    private int id;
    private String name;
    private Userdata SelectedUser;

    public UserdataController() {
   }
 //getters setters for id,name and SelectedUser

  private UserdataFacade getFacade() {
    return ejbFacade;
  }
  public List retrieveData() {
    List result = getFacade().findAll();
    return result;
  }

   public void create() {
    try {
        getFacade().create(current);
        JsfUtil.addSuccessMessage("Userdata created successfully");
    } catch (Exception e) {
        JsfUtil.addErrorMessage(e, "Persistence Error occured");
    }
  }
 }

The information available in PrimeFaces forum, NetBeans Sample code and Editable datable sample(mastertheboss.com/primefaces/datatables-with-primefaces/…;) helped me to create a better demonstrable CRUD dataTable with create,filter,edit and delete features. It would be incomplete without mentioning Mr.BalusC because his comments,solutions on JSF 2.x posts are valuable to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:16:07+00:00Added an answer on June 17, 2026 at 1:16 pm

    @PostConstruct annotation is used for init() method, based on NetBeans Sample Application ScrumToys.

    @PostConstruct
    public void init() {
    current = new Users();
    }

    The information PrimeFaces forum is also helped me to identify the problem in java code in the Model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new android app developer i want make app for tablets and phone
I'm trying to build a CRUD system using Hibernate. I want to build an
I'm a beginner in Grails development. I want to make a new simple MySQL
I want make datetimepicker in my project. Using jquery how it is possible? I
I want make a bash script which returns the position of an element from
I want make interactive application where user launches it and can do various task
Let's say I want make some of my sources publicly available via my blog
I have style sheet with a class name changebackgroundcolor i want make change in
Sorry google translate make mistake, to many mistake, i want make an alarm in
I am traversing a HTML document using javascript DOM. I want make a list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.