2013-04-20 95 views
0

我需要驗證<p:spinner>值是否在設定範圍之間。確認消息不再顯示

<p:spinner id="minutes" min="0" max="1000" value="#{printerSettings.t}" size ="1"> 
    <f:validateLongRange minimum="0" maximum="1000" /> 
    <p:ajax update="NewTime"/> 
</p:spinner> 
<h:message for="minutes" style="color:red" /> 

<p>Number of copies (Max of 50) : 
    <p:spinner id ="Copies" min="1" max="50" value="#{printerSettings.p}" size ="1"> <!-- allows the user a choice of up to 50, this is more than enough for any situation, if needed this can be removed or raised --> 
     <p:ajax update="p"/> 
     <f:validateLongRange minimum="1" maximum="50" /> 
    </p:spinner> 
    <div class="whiteSpace"/> 
    <h:outputText value="Copies that will be printed: &nbsp; #{printerSettings.p}" id="p"/> 

    <h:message for="Copies" style="color:red" /> 
</p> 

這是以前的工作,但現在沒有驗證發生,沒有錯誤等等,這是怎麼造成的,我該怎麼解決呢?

編輯

<div id="site_content"> 
     <div id="content"> 
      <h:body> 


       <h:form onsubmit="return validateForm()"> 
        <p> 

        In how many minutes time would you like to have your job sent to the printer ? 
        <div class="whiteSpace"/> 
        <p:spinner id="minutes" min="0" max="1000" value="#{printerSettings.t}" size ="1"> 
         <p:ajax update="NewTime"/> 
         <f:validateLongRange minimum="1" maximum="1000" /> 
        </p:spinner> 

        <h:message for="minutes" style="color:red" /> 

        <br></br> 
        <br></br> 

        The time the print job will be sent to the printer will be : 
        <!--<p:button actionListener="{otherBean.setTValue(printerSettings.t)}" value="Set Val" /> Currently causing an error --> 
        <br></br> 
        <h:outputText value="#{printerSettings.getNewTime()}" id="NewTime"/> 
        <br></br> 
        <br></br> 
        <p:commandButton type="submit" action="#{email.mail(printerSettings.t, printerSettings.p, printerSettings.paperSize, printerSettings.duplex, printerSettings.orienation, printerSettings.printer)}" onclick="Thankyou()" value="Print" /> 

<p:button outcome="index" value="Homepage" icon="ui-icon-home"> 
        </p:button> 

       </h:form> 
      </h:body> 
     </div> 
    </div> 
    <script type="text/javascript"> 

        function Thankyou() 
        { 
         alert("Sent to the printing holding queue, you may close this app now or carry on using this app, your work will still print out "); 
         //location.href = 'index.xhtml'; 

        } 

是可以嗎?我可以發佈,如果需要更多的代碼,在我的評論說,驗證似乎是工作,它只是現在顯示在所有

編輯

   <p:commandButton type="submit" update ="minutes2 Copies2" action="#{email.mail(printerSettings.t, printerSettings.p, printerSettings.paperSize, printerSettings.duplex, printerSettings.orienation, printerSettings.printer)}" onclick="Thankyou()" value="Print" /> 
+0

的可能重複的[如何驗證提交的旋轉器的值](http://stackoverflow.com/questions/16120189/how-to-validate-an-value-submitted-by-a-spinner )。如果那裏提供的答案沒有回答你所尋找的答案,那麼你首先不應該接受。 – 2013-04-20 21:19:55

+0

您是否希望在更改輸入或提交表單時顯示消息?目前,當您更改輸入時,它們確實不會顯示出來,但我不確定是否滿足您的要求,因爲代碼不具備完整的SSCCE風格(您應該提供足夠的代碼,以便其他人(和您自己!)可以在將所有內容設置爲默認值的情況下複製到完全空白的遊樂場項目中時準確再現您的問題)。 – BalusC 2013-04-20 21:20:41

+0

謝謝,我希望消息將在用戶按下提交後顯示,我已經通過測試代碼發現了,它確實驗證了輸入,如果值超過驗證的範圍,將不會提交,但沒有錯誤消息!將在一秒內發佈代碼 – user2292674 2013-04-20 21:31:34

回答

4

你確認並提交錯誤的消息ajax的形式,但你無處指示JSF更新ajax響應的消息組件。他們不會自行更新。

您需要給消息組件一個ID並在ajax更新中引用它們。

E.g.

<h:message id="foo" ... /> 

<p:ajax ... update="foo" /> 

<p:commandButton ... update="foo" /> 

您可以根據需要指定spaceseparated多個ID。

<p:commandButton ... update="foo bar" /> 
+0

非常感謝有消息顯示:),最後一個問題,提交我有一些顯示簡單消息的javascript,但總是顯示,只有在所有驗證完成後才顯示此消息。 – user2292674 2013-04-20 21:58:41

+2

在EL上下文中使用'#{facesContext.validationFailed}'或在JS中使用'args.validationFailed' PrimeFaces'oncomplete'的上下文。有關詳細的答案或新問題,請按「提問」按鈕,而不是濫用其他問題的評論。 – BalusC 2013-04-20 22:46:44