p:消息不显示在primefaces中的对话框内

时间:2017-04-21 14:31:22

标签: jsf primefaces dialog messages display

我在Primefaces 6的对话框中有一条p:消息,但是这个元素没有显示任何内容。它只是没有在屏幕上显示。我在bean中设置错误消息,但它不显示消息。我希望在对话框中显示错误消息。我已经尝试更新命令按钮和Bean中的p:消息。这是代码:

豆:

public void persist() {
    boolean error = false;
    addErrorMessage("schedule_summary_error_message", "FUMBLE! Something went wrong! Try it again.", null); // Added this line so the error message can show no matter what but it still doesn't show.

    for (int i=0; i < newMatchups.size(); i++) {
         if (!matchupService.persist(newMatchups.get(i)))
             error = true;
    }

    if (error) {
        addErrorMessage("schedule_summary_error_message", "Something went wrong! Try it again.", null);
    } else {
        reloadCurrentMatchups();
        RequestContext.getCurrentInstance().execute("PF('newScheduleDialog').hide()");
    }
}


private static void addErrorMessage(String clientId, String summary, String detail) {
    FacesContext context = FacesContext.getCurrentInstance();
    context.addMessage(clientId, new FacesMessage(Constant.ERROR, summary, detail));
}

XHTML:

<p:dialog id="newScheduleDialog" appendToBody="true" responsive="true" widgetVar="newScheduleDialog" header="Creating the game schedule" 
position="center top" closeOnEscape="true" width="60%" modal="true" style="overflow-y:auto;max-height:100%">
<p:ajax event="close" oncomplete="PF('createScheduleWizard').loadStep(PF('createScheduleWizard').cfg.steps[0], true)" />
   <h:form id="schedule_form">
      <p:wizard id="createScheduleWizard" widgetVar="createScheduleWizard" showStepStatus="false" flowListener="#{scheduleWizard.onFlowProcess}" showNavBar="false" >
        <p:tab id="summaryTab" title="Summary">
            <p:messages id="schedule_summary_error_message" for="schedule_summary_error_message" showDetail="true" showSummary="false" autoUpdate="true" closable="true" />                                                     
            <p style="text-align: center;" class="sansation_bold16">Summary </p> 

            <ui:include src="../pages/matchup_carousel.xhtml" />
            <p:commandButton value="Save and publish schedule" id="saveButton" widgetVar="saveButton" actionListener="#{matchupBean.persist}"
                              style=" -webkit-border-radius: 6px; border-radius: 6px; margin-top:20px"/>
        </p:tab>

    </p:wizard>
</h:form>

2 个答案:

答案 0 :(得分:1)

我之前没有见过在“for”属性中使用id与元素本身相同的id。尝试在消息的“for”中使用不同的id(可能是表单的id)。尝试:

<p:messages id="schedule_summary_error_message" for="schedule_summary" showDetail="true" showSummary="false" autoUpdate="true" closable="true" />   

并添加与表单ID相关联的消息:

addErrorMessage("schedule_summary", "Something went wrong! Try it again.", null);

答案 1 :(得分:0)

在添加代码中缺少的错误消息后,您需要添加javascript代码段以显示对话框。