2014-02-20 85 views
0

只是一個簡單的問題,而是一個很討厭我如何沒有彈出如果驗證失敗

基本上我有一些驗證,用戶必須在繼續之前選擇一個單選按鈕,當我按下提交按鈕我得到ajax消息告訴我,我需要選擇一個單選按鈕,但我也從彈出的命令按鈕通知用戶的標誌,有無論如何禁止彈出,除非驗證已成功

這是單選按鈕的代碼

<p:column> 
         <br></br> 
         <p:selectOneRadio id="radioButtons" value="#{formBean.number}" layout="grid" columns="1" required = "True" 
              requiredMessage="#{bundle.messageSelectMarkRange}" > 
          <f:selectItem itemLabel="0 - 19" itemValue="1" /> 
          <f:selectItem itemLabel="20 - 39" itemValue="2" /> 
          <f:selectItem itemLabel="40 - 49 " itemValue="4" /> 
          <f:selectItem itemLabel="50 - 59" itemValue="5" /> 
          <f:selectItem itemLabel="60 - 69" itemValue="6" /> 
          <f:selectItem itemLabel="70 - 79" itemValue="7" /> 
          <f:selectItem itemLabel="80 - 100" itemValue="8" /> 
          <p:ajax process="@this" update="mySpinnerPanel comments" /> 
         </p:selectOneRadio> 
        </p:column> 

,這是命令按鈕

 <p> 
      <p:commandButton value="#{bundle.buttonNextSection}" icon ="ui-icon-disk" update="displayMark :growl" oncomplete="PF('dlg').show()" /> 
     </p> 
     <p:dialog header="Confirm Mark" widgetVar="dlg" showEffect="fold" hideEffect="fold"> 
      <h:panelGrid id="displayMark" columns="2" cellpadding="5"> 
       <h:outputText value="Mark to be submitted: " /> 
       <h:outputText value="#{markingBean.markSectionOne.markSectionOne}" /> 
       <h:outputText value="For student number : " /> 
       <h:outputText value="#{markingBean.studentNumber}" /> 
       <p:commandButton action="#{markingBean.markSectionOne}" value="#{bundle.buttonSave}" update=":growl" icon="ui-icon-disk"/> 
       <!-- <p:button outcome="/lecturer/marking/marking-section-two" value="#{bundle.buttonNextSection}" icon ="ui-icon-arrowthick-1-e" /> 
       --> 
      </h:panelGrid> 
     </p:dialog> 

我只是想阻止對話框坡平了,如果驗證不成功

感謝

回答

2
<p> 
    <p:commandButton value="#{bundle.buttonNextSection}" icon="ui-icon-disk" 
     update="displayMark :growl checkValidation" /> 
</p> 

<p:panelGroup id="checkValidation"> 
    <h:outputScript rendered="#{facesContext.validationFailed}"> 
     PF('dlg').show(); 
    </h:outputScript> 
</p:panelGroup> 

<p:dialog header="Confirm Mark" widgetVar="dlg" showEffect="fold" hideEffect="fold"> 
    <h:panelGrid id="displayMark" columns="2" cellpadding="5"> 
     <h:outputText value="Mark to be submitted: " /> 
     <h:outputText value="#{markingBean.markSectionOne.markSectionOne}" /> 
     <h:outputText value="For student number : " /> 
     <h:outputText value="#{markingBean.studentNumber}" /> 
     <p:commandButton action="#{markingBean.markSectionOne}" 
      value="#{bundle.buttonSave}" update=":growl" icon="ui-icon-disk" /> 
     <!-- <p:button outcome="/lecturer/marking/marking-section-two" value="#{bundle.buttonNextSection}" 
      icon ="ui-icon-arrowthick-1-e" /> --> 
    </h:panelGrid> 
</p:dialog> 

參考:https://stackoverflow.com/a/15384529/1602621