验证消息不再显示

时间:2013-04-20 21:10:59

标签: validation jsf

我需要验证<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" />

1 个答案:

答案 0 :(得分:4)

您正在通过ajax验证并提交表单,但您无法指示JSF更新ajax响应上的消息组件。他们不会自己更新。

您需要为消息组件提供一个ID,并在ajax update中引用它们。

E.g。

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

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

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

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

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