Невозможно обновить Primefaces Datatable из commandButton внутри диалога - PullRequest
0 голосов
/ 06 марта 2019

Вот мой xhtml, который содержит данные и диалоговое окно в другом теге <h:form>

    <?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:body class="ad-bg-color">
        <h:form id="form">
            <p:dataTable id="dt_Questions" widgetVar="dt_QuestionswidgetVar"  reflow='true' binding="#{table}" var="currentrow" rowKey="#{currentrow[0]}" paginator="true" paginatorPosition="bottom" rows="10"  value="#{faqManagementBean.questiosLookupList}" resizableColumns="true" >
                <p:column headerText="Sr.No." styleClass='com-wdth-8'>
                    <h:outputText value="#{table.rowIndex + 1}" />
                </p:column>
                <p:column headerText="Question Text" filterBy="#{currentrow[1]}" filterMatchMode="contains" styleClass="questions">
                    <p:watermark for="@(.questions)" value="Search Questions" />
                    <h:outputText value="#{currentrow[1]}" title="#{currentrow[4]}"/>
                </p:column>
                <p:column headerText="Edit Question" styleClass="com-wdth-12">
                    <p:commandButton id="btn_Edit" onclick="pqr();" styleClass="btn ad-btn-secondary padd"  value="Edit" ajax="false" action="#{faqManagementBean.editQuestion(currentrow[0])}"></p:commandButton>
                </p:column>
                <p:column headerText="Action" styleClass="com-wdth-12">
                    <p:commandButton id="btn_EnterAnswer" title="#{currentrow[4]}" styleClass="btn ad-btn-secondary padd" value="#{currentrow[2]}" ajax="false" onclick="PF('answerDialog').show();" action="#{faqManagementBean.enterOrViewAnswer(currentrow[0],currentrow[3])}"></p:commandButton>
                </p:column>
            </p:dataTable>
        </h:form>
        <p:dialog id="dialog_answer" closable="true" header="Answer" visible="#{faqManagementBean.answerDialogBoxFlag}" rendered="#{faqManagementBean.answerDialogBoxFlag}" widgetVar="answerDialog" modal="true" styleClass="com-mr-lr15">
            <h:form id="form1">
                <div>
                    <h:outputLabel value="Question: #{faqManagementBean.questionTextForAnswerDialogLabel}"/>
                </div>
                <h:outputLabel value="Enter Answer"/>
                <div>
                    <p:inputTextarea value="#{faqManagementBean.answerText}" rows="3" cols="50"/>
                </div>
                <p:commandButton id="btn_SaveAnswer" class="btn ad-btn-primary padd" icon="fa fa-check" value="Save" action="#{faqManagementBean.saveAnswer}" rendered="#{faqManagementBean.answerDialogShowSaveButtonFlag}">
                    <p:ajax update=":form:dt_Questions" oncomplete=":form:PF('dt_QuestionswidgetVar').filter()"/>
                </p:commandButton>
                <p:commandButton id="btn_UpdateAnswer" class="btn ad-btn-primary padd" icon="fa fa-check" value="Update" ajax="false" action="#{faqManagementBean.updateAnswer()}" rendered="#{faqManagementBean.answerDialogShowUpdateButtonFlag}">
                    <p:ajax update="form:dt_Questions"/>
                </p:commandButton>
                <p:commandButton id="btn_ResetAnswer" ajax="false" value="Reset" styleClass="btn ad-btn-danger padd" icon="fa fa-refresh" actionListener="#{faqManagementBean.answerDialogReset()}"></p:commandButton>
                <p:commandButton id="btn_AnswerDialogCancel" class="btn ad-btn-danger padd" icon="fa fa-times" value="Cancel" ajax="false" action="#{faqManagementBean.answerDialogCancel()}"></p:commandButton>
            </h:form>
        </p:dialog>
    </h:body>
</html>

, а код кнопки «Сохранить» из вспомогательного компонента -

public void saveAnswer() {
        if (!answerText.trim().isEmpty()) {
            FAQMemberMasterDao obj = new FAQMemberMasterDao();
            obj.setMemberName(answerText.trim());
            obj.setSetGroupId(102);
            obj.setMemberType(2);//2 is used for Answer
            obj.setCreatedUserId(Integer.valueOf(sessionBean.getUserID()));
            obj.setCreatedDateTime(new Date());
            obj.setLastModifiedUserId(Integer.valueOf(sessionBean.getUserID()));
            obj.setLastModifiedDateTime(new Date());
            obj.setSessionId(sessionBean.getSessionId());
            obj.setStatus(1);
            new QueryforHqlandSql().save(obj);
            mapOfQuestionsAnswers_IdAndText.put(obj.getMemberId(), answerText.trim());
            mapOfQuestionsAnswers_TextAndId.put(answerText.trim(), obj.getMemberId());
            saveQuestionAnswerMapping(toBeActionedQuestionId, obj.getMemberId());
            answerDialogBoxFlag = false;
            answerDialogShowSaveButtonFlag = false;
            answerDialogShowUpdateButtonFlag = false;
            fetchDataForQuestionsLookupList();
            new Validator().showMessageForSuccess("Saved Successfully");
        }
        questionTextForAnswerDialogLabel = "";
    }

и fetchDataForQuestionsLookupList();выглядит следующим образом:

public void fetchDataForQuestionsLookupList() {
        System.out.println("fetchDataForQuestionsLookupList called");
        questiosLookupList.clear();
        String q = "from FAQMemberMasterDao where memberType=1 and status=1 order by memberId desc";
        List li = new QueryforHqlandSql().executeHQLQuery(q);
        if ((li != null) && (!li.isEmpty())) {
            for (int i = 0; i < li.size(); i++) {
                FAQMemberMasterDao obj = (FAQMemberMasterDao) li.get(i);;
                Object row[] = new Object[5];
                row[0] = obj.getMemberId();
                row[1] = obj.getMemberName();
                int temp = isAnswerExist(Integer.valueOf(row[0].toString()));
                if (temp == 0) {
                    row[2] = "Enter Answer";
                    row[3] = 0;
                    row[4] = "";
                } else {
                    row[2] = "View Answer";
                    row[3] = temp;
                    row[4] = mapOfQuestionsAnswers_IdAndText.get(temp);
                }
                questiosLookupList.add(row);
            }
        }
    }

После нажатия кнопки сохранения, диалоговое окно должно быть закрыто (которое закрывается идеально), и данные должны быть обновлены с ответом, введенным в <p:inputTextarea>, который присутствует внутри диалога.Я подтвердил, что данные заполняются в QuestiosLookupList .Единственная проблема заключается в том, что при нажатии на кнопку «Сохранить из диалогового окна» не отображаются данные.Если я перезагрузил страницу вручную, нажав ввод в URL, данные будут обновлены.Пожалуйста, помогите, так как я новичок в JSF и простых лицах.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...