需要将@ApplicationScoped bean“注入”Liferay钩子

时间:2012-07-11 18:25:55

标签: liferay-6

托管bean和钩子都在同一个战争中。我在Tomcat 7上使用6.1 CE。

我正在尝试在绑定到logout.events.pre的Hook的run方法中从ApplicationScoped bean中删除一些数据。

使用HttpServletRequest调用run方法,并且我已经读过bean应该作为HttpServletRequest的属性访问,或者我可以从HttpServletRequest获取ServletContext,但两个方法都返回null。

我列举了所有按键,但它不存在。

有谁知道如何实现我的需要?

感谢。

    @Override
public void run(HttpServletRequest req, HttpServletResponse res) {

    System.out.println("In custom pre LogoutAction....");

    ServletContext servletContext = req.getServletContext();

// DataBean dataBean =(DataBean)servletContext.getAttribute(“com.xvest.hooks.DataBean”);

// DataBean dataBean =(DataBean)req.getAttribute(“dataBean”);

    // Find loggedInUser and impersonatedUser.
    ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute("THEME_DISPLAY");

    User loggedInUser = themeDisplay.getRealUser();
    User impersonatedUser = themeDisplay.getUser();

    // Fetch CompleterHousehold for impersonatedUser.
    CompleterHousehold completerHousehold = dataBean.fetch(impersonatedUser, loggedInUser);

    // Delete loggedInUser from CompleteHousehold.viewers
    boolean result = completerHousehold.deleteViewer(loggedInUser);

    // If the delete returns true, there are no more viewers for this household, so delete the CompleterHousehold from DataBean.
    if (result)
        dataBean.delete(impersonatedUser);
}

0 个答案:

没有答案