PrimeFaces:关于审定条件更新 [英] PrimeFaces: conditional update on validation

查看:140
本文介绍了PrimeFaces:关于审定条件更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能有条件地更新JSF组件只有在验证成功?

我希望能够做这样的事情

 <电话号码:commandLink进程=@形式的监听器=#{FOO}
  更新=东西somethingElse>
 

,其中东西只得到更新,如果验证成功。

有没有什么办法可以做或者是,仅仅不支持的JSF?

我已经能够来搭起一种隐藏commandLinks一劈,但并不完全满意:

 <电话号码:commandLink进程=@形式的监听器=#{FOO}
  更新=somethingElse的onComplete =如果$(args.validationFailed!)(#链接)点击();>
<电话号码:commandLink风格=显示:无ID =链接
  更新=东西>
 

解决方案

< H:消息> (或PrimeFaces对应<电话号码:消息> )的intented这一点。或者,你的情况可能较好,< H:邮件> (或<电话号码:邮件>

 公共无效提交(){
    // ...

    如果(故障){
        FacesContext.getCurrentInstance()方法addMessage(空,
            新的FacesMessage(FacesMessage.SEVERITY_ERROR,失败,NULL));
    }
}
 

 < H:邮件ID =消息/>
<电话号码:commandLink进程=@形行动=#{bean.submit}更新=邮件的东西/>
 

请注意,你也应该用正常的验证执行情况进行验证。如果它抛出一个 ValidatorException ,则动作不会反正调用。里面的操作方法做验证是一种气味。

Is it possible to conditionally update JSF components only when validation succeeds?

I would like to be able to do something like

<p:commandLink process="@form" listener="#{foo}" 
  update="something somethingElse"> 

where "something" only gets updated if validation is successful.

Is there any way that can be done or is that just not supported in JSF?

I've been able to rig up kind of a hack with hidden commandLinks but not entirely satisfied:

<p:commandLink process="@form" listener="#{foo}" 
  update="somethingElse" oncomplete="if (!args.validationFailed) $("#link").click();">
<p:commandLink style="display:none" id="link"
  update="something">

解决方案

The <h:message> (or PrimeFaces' counterpart <p:message>) is intented for this. Or, in your case maybe better, the <h:messages> (or <p:messages>).

public void submit() {
    // ...

    if (fail) {
        FacesContext.getCurrentInstance().addMessage(null, 
            new FacesMessage(FacesMessage.SEVERITY_ERROR, "Fail", null));
    }
}

with

<h:messages id="messages" />
<p:commandLink process="@form" action="#{bean.submit}" update="messages something" />

Note that you're as well supposed to use a normal Validator implementation to perform the validation. If it throws a ValidatorException, then the action won't be invoked anyway. Doing validation inside action method is a smell.

这篇关于PrimeFaces:关于审定条件更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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