Creating Filter in custom portlet

Here we will do how access the portlet filter. These portlet filter which introduced in JSR-286.

We will go through the how to create filter in customportlet.

STEP:1

Here i am create the portlet filter when an action takes place i.e whenever there is an Action Request.

Create the class the "ActionJSONFilter" which implements "ActionFilter"

public class ActionJSONFilter implements ActionFilter
Also we can implement the RenderFilter also ResourceFilter. All these are in the javax.portlet.filter.*; package.

public class ActionJSONFilter implements ActionFilter {
public void destroy() {
System.out.println("destroy");
}
public void init(FilterConfig arg0) throws PortletException {
System.out.println("init");
}
public void doFilter(ActionRequest arg0, ActionResponse arg1,
FilterChain arg2) throws IOException, PortletException {
System.out.println("doFilter");
}
}

STEP:2

 Define the below entries in the portlet.xml , Here we need to define the filter class and lifecycle and portletname.


<filter>
 <filter-name>Action</filter-name>
 <filter-class>com.test.filter.json.ActionJSONFilter </filter-class>
 <lifecycle>ACTION_PHASE</lifecycle>
</filter>
<filter-mapping>
  <filter-name>Action</filter-name>
  <portlet-name>JSON</portlet-name>
</filter-mapping>
Deploy the portlet . we will observe the SOP of init() during the deployment.

Whenever we perform the Actonrequest we can able to see the SOP of doFilter().

Comments

Popular posts from this blog

Theme display in javascript

How to know which liferay version we are using

Viewing the SQL Query in liferay : debugging the SQL Query in Hibernate