简体   繁体   English

具有AJAX验证的JSF表单-重点问题

[英]JSF Form with AJAX validation - Focus issues

Hi JSF experts out there ... 嗨,JSF专家在那里...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui"
  xmlns:o="http://omnifaces.org/ui">
<h:head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
</h:head>
<h:body>
<h:form>
    <o:validateOneOrMore components="one two three" id="validate"/>
    <p:message for="validate"/>
    <p:inputText id="one" value="#{testBean.valueOne}">
        <p:ajax event="change" process="@this" update="@form"/>
    </p:inputText>
    <p:inputText id="two" value="#{testBean.valueTwo}">
        <p:ajax event="change" process="@this" update="two"/>
    </p:inputText>
    <p:inputText id="three" value="#{testBean.valueThree}">
        <p:ajax event="change" process="@this" update="one two validate"/>
    </p:inputText>
    <p:commandButton process="@form"
                     update="@form"
                     value="Submit"
                     partialSubmit="true"
                     action="#{testBean.submit}"/>
    </h:form>
</h:body>
</html>

a simple form with requirement of at least one form filled, immediate error reset and tab-able. 一种简单的表单,要求至少填写一张表单,立即重置错误并可以制表。

But i didn't get it work, tried different things as you can see in sample code. 但是我没有使它起作用,您尝试了一些不同的事情,如示例代码所示。

What happens 怎么了

  • hit submit -> error message shown: fine 点击提交->错误消息显示:很好
  • enter entry in field one and leave with tab: fine (all fields are not in error state anymore and message is gone) BUT focus lost after complete AJAX update. 在第一个字段中输入条目,然后使用制表符离开:正常(所有字段均不再处于错误状态,并且消息消失了),但在完成AJAX更新后失去了焦点。 Ok expected behavior of JSF and browsers as i read here, but how to solve? 我在这里读到的JSF和浏览器的预期行为还可以,但是如何解决?
  • delete all entries, hit enter -> input in field three and leave the field ... nothing changes ... even message is not gone sth. 删除所有条目,在第三个字段中按Enter键->输入,然后离开该字段...什么都没有改变...甚至消息都没有消失 i also do not understand, since i updated all fields 我也不明白,因为我更新了所有字段

Is there any solution out, for having a form like that ... where after each input validation of form will happen (meaning remove such global errors) and still have it quickly usable by using the tab-key? 对于这样的表单,是否有解决方案……在每次输入表单后都会进行验证(意味着删除此类全局错误),并且仍然可以使用Tab键快速使用它?

thx. 谢谢。

This is a very annoying issue, which has to do with the way JSF preforms partial renders, there is an in depth post regarding JSF 2 AJAX focus issues . 这是一个非常烦人的问题,与JSF预执行部分渲染的方式有关,关于JSF 2 AJAX焦点问题有深入的文章。

Which offers a potential solution in the form of using the JSF JavaScript API to listen for triggered AJAX request and refocusing, have a look at the post for further details. 通过使用JSF JavaScript API来侦听触发的AJAX请求和重新聚焦,它提供了一种潜在的解决方案,有关更多详细信息,请查看文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM