2017-04-21 33 views
0

プライムフェイス6のダイアログ内にp:メッセージがありますが、この要素はどのコンテンツも表示されていません。それは単に画面に表示されません。 Beanにエラーメッセージを設定していますが、メッセージは表示されません。エラーメッセージがダイアログ内に表示されるようにします。私は、コマンドボタン内とBean内のp:メッセージを更新しようとしました。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> 

答えて

1

同じ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); 
+0

ちょうどこれを試みたが、うまくいかなかった。メッセージはまだ表示されません。このp:messagesを追加したのは、データベーストランザクションやその他の例外で例外が発生したときにエラーメッセージを表示するためです。 – flacoding

0

あなたはあなたのコードに欠けているエラーメッセージを追加した後、ダイアログを表示するには、コードのjavascriptの部分を追加する必要があります。

+0

これは問題に関連する単なるコードです。この時点で、ダイアログはすでに表示されています。 – flacoding

+0

コマンドボタンはデフォルトでajax呼び出しをトリガーするので、ajaxの完了後にメッセージを更新するには、コマンドボタンのupdate属性を使用してメッセージコンポーネントを更新する必要があります。 – OTM

+0

ちょっと試しましたが動作しませんでしたが、理論上、メッセージにautoUpdate = "true"が設定されているので、これを行う必要はありません。 flacoding

関連する問題