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" />
4

1 回答 1

4

您正在通过 ajax 验证和提交表单,但您没有指示 JSF 在 ajax 响应中更新消息组件。他们不会自行更新。

您需要给消息组件一个 ID 并在 ajax 更新中引用它们。

例如

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

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

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

如有必要,您可以指定多个以空格分隔的 ID。

<p:commandButton ... update="foo bar" />
于 2013-04-20T21:48:44.733 回答