验证消息不再显示 [英] Validation messages do not show up anymore

查看:54
本文介绍了验证消息不再显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要验证<p:spinner>值是否在设定范围之间.

I need to validate if a <p:spinner> value is between a set range.

<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>

这以前曾经起作用,但现在没有进行验证,没有错误等.这是怎么引起的,我该如何解决?

This was working before, but now no validation happens, no error etc. How is this caused and how can I solve it?

编辑

 <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';

                    }

可以吗?我可以根据需要张贴更多代码,如我的评论中所述,验证似乎正在起作用,只是错误消息现在完全显示

is that ok ? i can post more code if required, as said in my comment the validation seems to be working, it is just the errors messages that are now displaying at all

编辑

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

推荐答案

您正在通过ajax验证并提交表单,但是您无处指示JSF在ajax响应中更新消息组件.它们不会自行更新.

You're validating and submitting the form by ajax, but you're nowhere instructing JSF to update the message components on ajax response. They do not update by themselves.

您需要给消息组件一个ID,并在ajax更新中对其进行引用.

You need to give the message components an ID and refer them in ajax update.

例如

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

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

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

如有必要,您可以指定多个ID空格.

You can if necessary specify multiple IDs spaceseparated.

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

这篇关于验证消息不再显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆