首页 文章

Primefaces / jsf中的条件更新

提问于
浏览
4

首先,所以没有误解,虽然这是同一个问题,因为PrimeFaces: conditional update on validation,因为虽然它可能已经给了原始海报一个解决方法,但它没有't really answer the question, and this workaround doesn'为我工作 .

所以,这是我的问题:我如何根据submition的结果有条件地更新primefaces组件?

我有一个组件,在任何情况下都不能更新,除非验证成功并且后端代码已成功执行 . (即,如果验证成功但后端存在SQL异常,则组件仍不应更新) .

为什么_2596369成功它将被更新为与点击提交按钮之前相同的事情 . Because I can't. 它's the captcha component. If you update it via ajax, it disappears, end of story. There was a ticket opened at Primefaces and they closed it as won' t修复,因为闪存组件不应该用ajax更新 .

因此,当我提交表单时,除非逻辑成功,否则我需要单独保留验证码 . 如果逻辑成功,我需要确保验证码在屏幕外消失 . 什么是最简单,最干净的方法?

如果这是一个n00b问题,请原谅 . 我是Primefaces和JSF的新手 .

3 回答

  • 9

    您可以在辅助bean中使用变量并在xhtml部分上使用它 .
    像这样:

    update="#{backingMB.updateString}"
    

    所以,在条件之后你可以把 updateString 的值,但是当你在 backingMB 上定义它时,你需要把它作为:

    String updateString=""; // this will be id of the component to be updated
    

    这样你就不会得到NullPointerException .

  • 1

    您可以结合使用JavaScript和RemoteCommand:

    <p:commandLink action="#{bean.doIt()}" process="@form" update="@none" oncomplete="if(!args.validationFailed){updateMyImportantUI();}" />
    
    <p:remoteCommand name="updateMyImportantUI" process="@this" update=":myImportantID" />
    
  • 9
    RequestContext.getCurrentInstance().update("clientId")
    

    有助于条件更新 .

    重新尝试

    RequestContext.getCurrentInstance().execute("Recaptcha.destroy()");
    

相关问题