论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Greg Montano
log4javascript for Liferay/JSF
2013年3月20日 上午6:28
答复

Greg Montano

等级: New Member

帖子: 8

加入日期: 2013年2月12日

最近的帖子

Hi,

I am trying to integrate Javascript logging for my application and found the log4javascript (http://log4javascript.org).

From the quickstart page (http://log4javascript.org/docs/quickstart.html), it says

var ajaxAppender = new log4javascript.AjaxAppender(URL);
log.addAppender(ajaxAppender);


where URL is some code that will handle the Javascript Log.
I have seen codes using JSP, Servlets and JSON but interested with how it will be done with JSF.

Anybody has tried this with Liferay/JSF? You assistance is highly appreciated. emoticon

Thanks.
Neil Griffin
RE: log4javascript for Liferay/JSF
2013年3月20日 上午8:30
答复

Neil Griffin

LIFERAY STAFF

等级: Liferay Legend

帖子: 2335

加入日期: 2005年7月26日

最近的帖子

Are you wanting to send JavaScript log messages to a URL on the server?
Greg Montano
RE: log4javascript for Liferay/JSF
2013年3月20日 下午7:34
答复

Greg Montano

等级: New Member

帖子: 8

加入日期: 2013年2月12日

最近的帖子

Yes, Neil.

I want to send a JavaScript Log messages to a URL on the server.
This URL will be the one to handle the messages and write/append these to a log file.
The JavaScript is on the same server as the URL.

Thanks.
Neil Griffin
RE: log4javascript for Liferay/JSF
2013年3月21日 上午10:09
答复

Neil Griffin

LIFERAY STAFF

等级: Liferay Legend

帖子: 2335

加入日期: 2005年7月26日

最近的帖子

Here is how I would recommend doing this for a JSF portlet.

In your main Facelet view (XHTML), do the following:

1<portlet:resourceURL var="loggerResourceURL">
2    <portlet:param name="log4javascript" value="true" />
3</portlet:resourceURL>
4<script>
5var ajaxAppender = new log4javascript.AjaxAppender(#{loggerResourceURL});
6log.addAppender(ajaxAppender);
7</script>


That will setup the javascript logging framework to log messages back to a URL that your JSF portlet can handle.

In order to handle the portlet ResourceRequest that will occur when the JavaScript engine of the browser invokes the URL...

 1package com.foo.bar;
 2
 3public class LoggerPortlet extends GenericFacesPortlet {
 4
 5    @Override
 6    public void serveResource(ResourceRequest resourceRequest,
 7            ResourceResponse resourceResponse) throws PortletException,
 8            IOException {
 9       
10        String log4javascript = resourceRequest.getParameter("log4javascript");
11        if (Boolean.TRUE.equals(log4javascript)) {
12            // handle logging
13        }
14        else {
15            super.serveResource(resourceRequest, resourceResponse);
16        }
17    }
18}


Then in your WEB-INF/portlet.xml descriptor you would have to specify:

<portlet-class>com.foo.bar.LoggerPortlet</portlet-class>

Now, there is another way of handling this that is more "JSF"ish, which would be to create a Resource and ResourceHandler. But the serveResource way might be good enough for your requirements.