jsf - JSF 应用程序的审计跟踪 - 全局 valueChangeListener 可能吗?

标签 jsf jpa jsf-2 audit-trail

我正在尝试为我的 Web 应用程序实现审计跟踪功能,该功能记录:

  • lastModified(时间戳)
  • modifiedBy(用户信息)
  • userComment(值变化的原因)

  • 对于我的每个输入字段(输入字段分布在具有不同支持 bean 和不同 valueHolder 类的多个表单中)。

    前两个(lastModified 和 modifiedBy)在 JPA AuditListener 和 @PrePersit 和 @PreUpdate 方法的帮助下很容易完成。

    第三个有点棘手,因为它需要用户交互。最好是一个要求用户评论的对话框。

    所以有(至少)两个悬而未决的问题:我可以为我的应用程序中的所有输入字段建立一个“全局”valueChangeListener 吗?这是否可以不附加 <f:valueChangeListener>每个输入组件?第二:如何获取用户评论。我的想法是放一个 p:dialog在我的网页模板中,但此对话框需要知道它是从哪个输入组件调用的。

    最佳答案

    Can I establish a "global" valueChangeListener for all input fields in my application? Is this possible without attaching to each single input component?



    是的,有 SystemEventListener PreRenderViewEvent 期间执行.您需要遍历由 FacesContext#getViewRoot() 获得的组件树。查找所有 instanceof 的组件 EditableValueHolder (或更细粒度的)然后添加 new YourValueChangeListener() addValueChangeListener() 方法。另请参阅此答案如何注册系统事件监听器:How to apply a JSF2 phaselistener after viewroot gets built?

    Second: How can I grab the user comment. My idea is to put a p:dialog in my web page template but this dialog needs to know from which input component it is called.



    您可以在 YourValueChangeListener#processValueChange()将有问题的组件设置为您通过 evaluateExpressionGet() 抓取的某个请求或 View 范围的属性.
    Recorder recorder = (Recorder) context.getApplication().evaluateExpressionGet(context, "#{recorder}", Recorder.class);
    recorder.setComponent(event.getComponent());
    // ...
    

    如有必要,它将执行 EL 并在其范围内自动创建 bean。反过来,bean 还应该持有代表用户评论的属性。最后,您可以在您的 <p:dialog> 中使用它.
    <p>You have edited #{recorder.component.label}, please mention the reason:</p>
    ...
    <h:inputText value="#{recorder.comment}" />
    

    关于jsf - JSF 应用程序的审计跟踪 - 全局 valueChangeListener 可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7473126/

    相关文章:

    jsf - :graphicImage images not displayed

    java - 有条件渲染 <h :commandButton> using <c:if>

    jsf - 组件类型 javax.faces.SelectOne(underwriters) 需要 UISelectItem/UISelectItems 的子组件类型

    mysql - Hibernate:向mysql数据库添加日期属性,它将作为前一天插入数据库

    jsf - 单击 primefaces 中的字段集后如何调用方法?

    java - 在 View 之间传递对象

    java - JRE 6 不支持漂亮面孔

    java - JPA中惰性对象的奇怪初始化

    javascript - 将 JS 操作与 JSF 同步

    java - JPA中的并发问题