Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 如何向编程生成的primefaces组件添加ajax验证_Jsf_Jsf 2_Primefaces - Fatal编程技术网

Jsf 如何向编程生成的primefaces组件添加ajax验证

Jsf 如何向编程生成的primefaces组件添加ajax验证,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,我试图将普通bean验证附加到以编程方式生成的组件上的blur事件 如果我使用xhtml手动创建组件,效果很好,如下所示: <p:inputText id="customerName" value="#{editCustomerBean.name}" label="Name"> <p:ajax async="true" event="blur" update="customerName, customerNameMsg" /> </p:inputText&g

我试图将普通bean验证附加到以编程方式生成的组件上的blur事件

如果我使用xhtml手动创建组件,效果很好,如下所示:

<p:inputText id="customerName" value="#{editCustomerBean.name}" label="Name">
    <p:ajax async="true" event="blur" update="customerName, customerNameMsg" />
</p:inputText>
当我以这种方式生成这个组件时,我看到一个在blur事件中发送到服务器的请求,但没有进行验证。发布的请求看起来与我在xhtml中指定组件时发送的请求相同:

javax.faces.partial.ajax=true&javax.faces.source=mainForm%3AcustomerName&javax.faces.partial.execute=mainForm%3AcustomerName&javax.faces.partial.render=mainForm%3AcustomerName+mainForm%3AcustomerNameMsg&javax.faces.behavior.event=blur&javax.faces.partial.event=blur&mainForm%3AcustomerName=&javax.faces.ViewState=8176624577669857830%3A-4154840965136338204

我在这个网站和Primefaces论坛上看到过类似的问题,但它通常涉及到在AjaxBehavior上附加一个侦听器方法,这不是我在这里要做的。我希望在未指定侦听器时,该行为与标记相同,这是为了验证字段。

结果表明,我查看ajax组件的时候弄错了树。今天我意识到我的组件也没有在提交时得到验证。事实证明,在动态创建JSF组件时,需要手动向组件注册BeanValidator。多亏了victor herrera对这个问题的回答:

结果发现我在看ajax组件时找错了方向。今天我意识到我的组件也没有在提交时得到验证。事实证明,在动态创建JSF组件时,需要手动向组件注册BeanValidator。感谢victor herrera对这个问题的回答:

动态添加模糊事件示例

   Message message=new Message();
    message.setId("msg");
    InputText it = new InputText();
    it.setId("input1");
    it.setRequired(true);
    message.setFor(it.getId());

    //******Setting validation render at onBlur event
    AjaxBehavior ajaxBehavior=new AjaxBehavior();
    ajaxBehavior.setAsync(true);
    ajaxBehavior.setUpdate(message.getId());
    it.addClientBehavior("blur", ajaxBehavior);
    //************************************************

动态添加onBlur事件的示例

   Message message=new Message();
    message.setId("msg");
    InputText it = new InputText();
    it.setId("input1");
    it.setRequired(true);
    message.setFor(it.getId());

    //******Setting validation render at onBlur event
    AjaxBehavior ajaxBehavior=new AjaxBehavior();
    ajaxBehavior.setAsync(true);
    ajaxBehavior.setUpdate(message.getId());
    it.addClientBehavior("blur", ajaxBehavior);
    //************************************************