update datatable dinamicaly every time I insert in it

UI Components for JSF
Post Reply
peter78
Posts: 8
Joined: 19 May 2016, 19:45

22 Jul 2016, 20:35

I have a datatable that initially uploads from an arraylist, which in turn uploads from an sqlite database. There are a few fields and buttons to interact with the database. I'm trying to make it work that the table displayed is automatically refreshed and displayed every time an insert or any other functions are executed. I tried to use <p:poll> to refresh the table constantly but it did not work, and I tried to use <p:ajax> but kept getting an error that the ajax event does not exist.

Here's one of the buttons:

Code: Select all

<p:fieldset legend="Insert" toggleable="true" toggleSpeed="500" collapsed="true" >
                 <h:panelGrid columns="4" style="margin-bottom:10px" cellpadding="5">
                    <h:outputText value="Enter formula:" />
                    <p:inputText placeholder="f(t) = t" value="#{support.userInputFormula}"/>
                    <p:commandButton id="insert" value="Insert" action="#{support.insert(support.userInputFormula)}" update="displayInsert"/>
                    <p:ajax event="insert" update="displayTable" listener="#{support.updateTable}"/>
                    <h:outputText id="displayInsert" value="#{support.outputText}" style="color: #{support.textColor == 'yes' ? 'green' : 'red'};" />
                </h:panelGrid>
            </p:fieldset>
and here's the table:

Code: Select all

<p:dataTable var="table" value="#{dtPaginatorView.formulas}" rows="10"
                         paginator="true"
                         paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                         rowsPerPageTemplate="5,10,15" resizableColumns="true" >
                <p:column headerText="Id" style="width:25%">
                    <h:outputText value="#{table.id}" />
                </p:column>
                <p:column headerText="Formula" >
                    <h:outputText value="#{table.formula}" />
                </p:column>
            </p:dataTable>
Primefaces version 6.0
JSF 2.2
Netbeans IDE 8.1
Apache Tomcat or TomEE

peter78
Posts: 8
Joined: 19 May 2016, 19:45

08 Aug 2016, 17:10

The way I fixed it is I had to repopulate the List every time I used the button on the UI and update the datatable. All I had to do is add this method to the PaginatorView class

Code: Select all

public static void update(){
        formulas = service.tableList();
    }
Primefaces version 6.0
JSF 2.2
Netbeans IDE 8.1
Apache Tomcat or TomEE

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 52 guests