仅使用 Primefaces 数据表对 JSF 进行操作审计

发布于 2024-10-20 18:26:10 字数 3561 浏览 2 评论 0原文

我目前正在审核项目上的用户操作,但遇到以下问题。
有一个名为“审核日志”的功能,它列出了用户在我的系统上执行的完整审核操作集。每当某个用户列出审核日志时,此操作也需要审核。
审核日志的 JSF 页面如下:

<ui:composition ...>
    <ui:define name="content">
        <h:form id="audit_List">
            <h:panelGrid columns="1">
                <p:breadCrumb>
                    <p:menuitem value="#{i18n['xxx']}" url="index.xhtml" />
                    <p:menuitem value="#{i18n['yyy']}"/>
                </p:breadCrumb>
                <p:panel header="#{i18n['zzz']}">
                    <p:dataTable var="auditEntry"
                                 value="#{auditList.allAuditEntries}"
                                 paginator="true"
                                 rows="10"
                                 paginatorPosition="top"
                                 dynamic="false">
                        <p:column sortBy="#{i18n[auditEntry.category]}"
                                  filterBy="#{i18n[auditEntry.category]}">
                            A column here
                        </p:column>
                        <p:column sortBy="#{auditEntryDescriptionI18N[auditEntry]}"
                                  filterBy="#{auditEntryDescriptionI18N[auditEntry]}">
                            A column here
                        </p:column>
                        <p:column sortBy="#{auditEntry.username}"
                                  filterBy="#{auditEntry.username}">
                            A column here
                        </p:column>
                        <p:column id="problematicColumn" 
                              sortBy="#{auditEntry.occurredOn}"
                              filterBy="#{auditEntry.occurredOn}">
                              <f:facet name="header">
                                       <h:outputText value="#{i18n['aaa']}"/>
                              </f:facet>
                              <h:outputText value="#{auditEntry.occurredOn}">
                                            <f:convertDateTime type="date"
                                                   ___I suspect pattern is giving the problem..___
                                                  pattern="{auditList.listDateFormat.stringValue}"
                                                  timeZone="#{sessionBean.serverTimeZone}"/>
                               </h:outputText>
                         </p:column>
                    </p:dataTable>
                </p:panel>
            </h:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>

我当前对特定代码片段进行审核操作:

<p:dataTable var="auditEntry"
             value="#{auditList.allAuditEntries}"
             paginator="true"
             rows="10"
             paginatorPosition="top"
             dynamic="false">

我的支持 bean:

public List<AuditEntry> getAllAuditEntries()
    {
        auditFacade.createAuditEntry(function that creates an audit entry);
        return allAuditEntries;
    }

对支持 bean 的指定操作执行审核的问题如下: 淹没审核日志 1 Flooded Audit Log 2

需要一种方法来注册一次查询审核日志,而不是图像上显示的那样。有什么想法吗?有什么方法可以使用 JSF 或相关标签来保证上述内容?

TL;DR JSF 页面上只有一个 PrimeFaces 数据表,如何以在单行上进行审核注册的方式审核此类页面的打开,而不是如图所示。
Pd:重新编辑所有重复的审计条目并按时间差过滤它们是不可行的

I am currently auditing the user actions on a project and I am having the following Issue.
There is a functionality called Audit Log, which lists the complete set of Audited actions performed by the user on my system. Whenever a certain user lists the Audit Log this action needs to be Audited as well.
The JSF page the Audit Log is made is the following:

<ui:composition ...>
    <ui:define name="content">
        <h:form id="audit_List">
            <h:panelGrid columns="1">
                <p:breadCrumb>
                    <p:menuitem value="#{i18n['xxx']}" url="index.xhtml" />
                    <p:menuitem value="#{i18n['yyy']}"/>
                </p:breadCrumb>
                <p:panel header="#{i18n['zzz']}">
                    <p:dataTable var="auditEntry"
                                 value="#{auditList.allAuditEntries}"
                                 paginator="true"
                                 rows="10"
                                 paginatorPosition="top"
                                 dynamic="false">
                        <p:column sortBy="#{i18n[auditEntry.category]}"
                                  filterBy="#{i18n[auditEntry.category]}">
                            A column here
                        </p:column>
                        <p:column sortBy="#{auditEntryDescriptionI18N[auditEntry]}"
                                  filterBy="#{auditEntryDescriptionI18N[auditEntry]}">
                            A column here
                        </p:column>
                        <p:column sortBy="#{auditEntry.username}"
                                  filterBy="#{auditEntry.username}">
                            A column here
                        </p:column>
                        <p:column id="problematicColumn" 
                              sortBy="#{auditEntry.occurredOn}"
                              filterBy="#{auditEntry.occurredOn}">
                              <f:facet name="header">
                                       <h:outputText value="#{i18n['aaa']}"/>
                              </f:facet>
                              <h:outputText value="#{auditEntry.occurredOn}">
                                            <f:convertDateTime type="date"
                                                   ___I suspect pattern is giving the problem..___
                                                  pattern="{auditList.listDateFormat.stringValue}"
                                                  timeZone="#{sessionBean.serverTimeZone}"/>
                               </h:outputText>
                         </p:column>
                    </p:dataTable>
                </p:panel>
            </h:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>

I have currently the Auditing action on the particular code snippet:

<p:dataTable var="auditEntry"
             value="#{auditList.allAuditEntries}"
             paginator="true"
             rows="10"
             paginatorPosition="top"
             dynamic="false">

My backing bean:

public List<AuditEntry> getAllAuditEntries()
    {
        auditFacade.createAuditEntry(function that creates an audit entry);
        return allAuditEntries;
    }

The problem of performing the auditting on the named action of the backing bean is the following:
Flooded Audit Log 1
Flooded Audit Log 2

Need a way to have the registration of consulting the Audit Log just once, and not as it is being shown on the images. Any ideas? Any way to user a JSF or related tag that will guarantee the above?

TL;DR Having just a PrimeFaces DataTable on a JSF page, how to audit the opening of such page in a way to have the audit registration on a single row, not as shown on the images.
Pd: It isnt feasible to re-edit all the repetitive audit entries filtering them by time difference

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡淡離愁欲言轉身 2024-10-27 18:26:11

如果可以将 ManagedBean 放入 RequestScope 中,您可以在 bean 的构造函数中调用 createAuditEntry 方法。然后每个请求只调用一次。

问候。

if it is possible to put the ManagedBean in RequestScope you could call the createAuditEntry method in the bean`s constructor. Then it is only called once per request.

Regards.

溺孤伤于心 2024-10-27 18:26:11

解决了我的问题。
支持 bean 现在是 ViewScoped,我刚刚创建了一个布尔变量,它确保每个 Bean ViewScope 周期仅执行一次审核。

public List<AuditEntry> getAllAuditEntries()
    {
        if (!isViewed)
        {
            isViewed = true;
            auditFacade.createAuditEntry(
                __creates Audit Entry here__);
        }

        return allAuditEntries;
    }

Solved my problem.
The backing bean is now ViewScoped and I just created a Boolean variable which ensures the Auditing is only done once per Bean ViewScope cycle.

public List<AuditEntry> getAllAuditEntries()
    {
        if (!isViewed)
        {
            isViewed = true;
            auditFacade.createAuditEntry(
                __creates Audit Entry here__);
        }

        return allAuditEntries;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文