简体   繁体   中英

p:messages not displaying inside a dialog in primefaces

I have ap:messages inside a dialog in Primefaces 6 but this element is not being displayed with any content. It just doesn't diplay in the screen. I'm Setting the error message in a bean but it does not display the message. I want the error message to show inside the dialog. I've tried updating the p:messages inside the commandbutton and in the Bean. Here is the code:

Bean:

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>

I haven't seen before to use the id in "for" attribute with the same id of the element itself. Try use a different id (form's id maybe) on the messages's "for". Try:

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

and add the message tied to the form's id:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM