简体   繁体   English

p:消息未显示在对话框中

[英]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. 我在Primefaces 6的对话框中有ap:messages,但此元素未显示任何内容。 It just doesn't diplay in the screen. 它只是不会在屏幕上显示。 I'm Setting the error message in a bean but it does not display the message. 我正在Bean中设置错误消息,但它不显示该消息。 I want the error message to show inside the dialog. 我希望错误消息显示在对话框中。 I've tried updating the p:messages inside the commandbutton and in the Bean. 我尝试过更新命令按钮内部和Bean中的p:messages。 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: 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. 我之前从未见过在“ for”属性中使用与元素本身相同的ID的ID。 Try use a different id (form's id maybe) on the messages's "for". 尝试在邮件的“ for”上使用其他ID(可能是表单的ID)。 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: 并添加与表单ID绑定的消息:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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