无法从对话框中的commandButton更新Primefaces Datatable

时间:2019-03-06 11:22:29

标签: jsf primefaces

这是我的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>

,备用Bean的“保存”按钮代码为

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中按Enter手动重新加载页面,则数据表将得到更新。 请帮助,因为我是JSF和primeface的新手。

0 个答案:

没有答案