1

I have a bean:

@ManagedBean
@SessionScoped
public class MainTable
{

    static List<MainTableRow> rows;

    public MainTable()
    {
        rows = new ArrayList<>();
    }

    public static boolean addRow(MainTableRow mainTableRow)
    {
        return rows.add(mainTableRow);
    }

    public List<MainTableRow> getRows()
    {
        return rows;
    }

    public void setRows(List<MainTableRow> rows)
    {
        MainTable.rows = rows;
    }
}

And my xhtml page is:

<h:body>
    <h3>Query Modeling Tool - Select Excel file</h3>
    <h:form>
        <p:fileUpload
            fileUploadListener="#{fileUploadController.handleFileUpload}"
            mode="advanced" dragDropSupport="false" update="messages"
            sizeLimit="10000000" fileLimit="3" allowTypes="/(\.|\/)(xls)$/"
            style="font-size: 14px" />

        <p:growl id="messages" showDetail="true" />

        <p:dataTable id="dataTable" var="mainTableRow"
            value="#{mainTable.rows}" style="font-size: 14px">
            <f:facet name="header">Main Table</f:facet>

            <p:column sortBy="" headerText="Index">
                <h:outputText value="#{mainTableRow.index}" />
            </p:column>
            <p:column sortBy="" headerText="Query">
                <h:outputText value="#{mainTableRow.query}" />
            </p:column>
            <p:column sortBy="" headerText="S1">
                <h:outputText value="#{mainTableRow.s1}" />
            </p:column>
            <p:column sortBy="" headerText="S2">
                <h:outputText value="#{mainTableRow.s2}" />
            </p:column>
            <p:column sortBy="" headerText="S3">
                <h:outputText value="#{mainTableRow.s3}" />
            </p:column>
            <p:column sortBy="" headerText="S9">
                <h:outputText value="#{mainTableRow.s9}" />
            </p:column>
            <p:column sortBy="" headerText="Uygunluk">
                <h:outputText value="#{mainTableRow.uygunluk}" />
            </p:column>
            <p:column sortBy="" headerText="Kural">
                <h:outputText value="#{mainTableRow.kural}" />
            </p:column>
            <p:column sortBy="" headerText="Kaynak">
                <h:outputText value="#{mainTableRow.kaynak}" />
            </p:column>
            <p:column sortBy="" headerText="Query Type">
                <h:outputText value="#{mainTableRow.queryType}" />
            </p:column>
            <p:column sortBy="" headerText="User Intent">
                <h:outputText value="#{mainTableRow.userIntent}" />
            </p:column>

        </p:dataTable>

    </h:form>

</h:body>

"rows" in MainTable is filled by another class, after uploading a file. After uploading I want to refresh dataTable without clicking any button. How can I do it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
yetAnotherSE
  • 3,178
  • 6
  • 26
  • 33

1 Answers1

2

It can be solved by one of the following points:

1. <p:fileUpload> has an attribute update that is used to ajax-update the components with a specified list of comma/space-separated ids, so you need to add id of your data table to that attribute:

<p:fileUpload ... update="messages dataTable" />

2. When a file has been uploaded, the table can also be updated programmatically in your action method:

RequestContext context = RequestContext.getCurrentInstance();
context.addPartialUpdateTarget("<path_to_your_table>");

See also:

Community
  • 1
  • 1
Rong Nguyen
  • 4,143
  • 5
  • 27
  • 53