如何在没有Seam的情况下访问Hibernate Envers中的FacesContext? [英] How to access FacesContext in Hibernate Envers without Seam?
问题描述
$ b $ ul
这是我们的自定义修订版实体
@Entity
@RevisionEntity(CustomRevisionListener.class)
公共类CustomRevisionEntity {
@Id
@GeneratedValue
@RevisionNumber
private int id;
私人字符串登录;
getters / setters ...
}
自定义修订监听器
public class CustomRevisionListener实现RevisionListener {
@Override
public void newRevision(Object revisionEntity) {
CustomRevisionEntity rev =(CustomRevisionEntity)revisionEntity;
//我们如何获得FacesContext /远程用户?
rev.setLogin(unknown);
我们已经尝试了注入和范围确定无济于事,我们也尝试了这个 ClassLoader解决方案,但是getCurrentInstance()仍然为null;
感谢您的帮助!
adamw是正确的,FacesContext.getCurrentInstance()在定制的RevisionListener中工作。
我们有一个javax.servlet.Filter实现试图处理doFilter()方法中的事务,该方法由于任何原因导致FacesContext.getCurrentInstance()返回null RevisionListener。我们昨天从web.xml中删除了它,原因不同,当我今天早上尝试getCurrentInstance()时没有它,一切正常。
感谢大家的回复,也许这有助于别人。
We're implementing Envers in our project for database auditing, and have run into a snag. We don't know how to determine what user is making the change. All the examples I can find use Seam and their Component.getInstance technique.
- Glassfish 3.1.2.2
- Mojarra 2.1.13
- Hibernate 4.1.6.Final
Here's our custom Revision Entity
@Entity
@RevisionEntity(CustomRevisionListener.class)
public class CustomRevisionEntity {
@Id
@GeneratedValue
@RevisionNumber
private int id;
private String login;
getters/setters...
}
And out custom Revision Listener
public class CustomRevisionListener implements RevisionListener {
@Override
public void newRevision(Object revisionEntity) {
CustomRevisionEntity rev = (CustomRevisionEntity) revisionEntity;
//how do we get the FacesContext/remote user?
rev.setLogin("unknown");
}
}
We've tried injection and scoping to no avail, we also attempted this ClassLoader solution I found for something that seemed to be a similar circumstance, but getCurrentInstance() was still null;
Thanks for your help!
adamw was correct, FacesContext.getCurrentInstance() does work in a custom RevisionListener.
We had a javax.servlet.Filter implementation attempting to handle the transaction in the doFilter() method which was for whatever reason causing FacesContext.getCurrentInstance() to return null in the RevisionListener. We removed that from the web.xml yesterday for a different reason and when I tried getCurrentInstance() without it this morning, everything works fine.
Thanks for the replies everyone, maybe this will help someone else someday.
这篇关于如何在没有Seam的情况下访问Hibernate Envers中的FacesContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!