Thursday, December 5, 2013

Liferay admin detection, community admin, Organization admin

If you see any portlet, it used to have four button 1. Preference 2. Maximise 3. Minimise 4. Close.
Only those user who has admin privilege, can see those button or will have able to change preference.

If user has community admin/owner, organization admin/owner, they can also see those button on their respective page. So, there are many combination like
user will not have admin privilege but have community admin then which kind of button they can see.

Now, if you have to developer one button and condition is that only admin(super admin, comminity admin, organization admin) can see that button, then before showing
that button, you have to whether logged in user has admin facility or not.

Liferay has given one API by which you can easily find out, use below code:

public boolean isUserLiferayAdmin(){
      PortletContextImpl portletContext = (PortletContextImpl)context;
      ThemeDisplay themeDisplay= (ThemeDisplay)portletContext.getRequest().getAttribute(WebKeys.THEME_DISPLAY);
      PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
      Long groupId = themeDisplay.getLayout().getGroupId();
      boolean isAnyLiferayAdmin = false;
       try {
   isAnyLiferayAdmin = GroupPermissionUtil.contains(permissionChecker,groupId, ActionKeys.MANAGE_LAYOUTS);
    }catch (Exception e1) {
     isAnyLiferayAdmin = false;
      return isAnyLiferayAdmin;

you can write this method in, so all the user defined portlet can user this method.

Other way is also there to determine admin previlages:

    List roles = user.getRoles();
    String isAdmin  = "false";
    for(Role role:roles){
    if(role.getName().equals("Administrator")) {isAdmin = "true";break;}
  }catch(Exception e){
   log.error("Not able to fetch Liferay user group info");

Tuesday, June 25, 2013

java.lang.NullPointerException at

Very small post, actually I got this error (java.lang.NullPointerException at while hitting REST web service. I searched a lot and spent all most one day but could not get reason behind it.

Finally one got solution, so thought to share with you, it may be helpful some time.

Jersey uses the thread context class loader to load such classes. Perhaps you can do the following:

Thread .currentThread ().setContextClassLoader(this.getClass().getClassLoader()); 

Put the above line code, just before you hit the REST.

For Example:
Thread .currentThread ().setContextClassLoader(this.getClass().getClassLoader());
webResource = client.resource("your REST server URL");
client.addFilter(new HTTPBasicAuthFilter("serverUserName", "serverPassword"));

if (response.getStatus() != 200) {
   throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());

String output = response.getEntity(String.class);

If you some other solution, then please share.


Binod Suman

Tuesday, May 14, 2013

Google Apps Engine Failed to compile jsp files.

My Google Apps Engine was working fine till I installed Windows 7 (62 bit). After shifting to Windows 7, when I tried to deploy my GAE code to google, I got below error:

------------ Deploying frontend ------------

Preparing to deploy:
Created staging directory at: 'C:\Users\sbinod\AppData\Local\Temp\appcfg5079868666950863187.tmp'
Scanning for jsp files.
Compiling jsp files. Failed to compile jsp files.
May 15, 2013 8:04:53 AM org.apache.jasper.JspC initClassLoader
WARNING: TLD files should not be placed in /WEB-INF/lib
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.jasper.JspCompilationContext.createCompiler(
at org.apache.jasper.JspCompilationContext.createCompiler(
at org.apache.jasper.JspC.processFile(
at org.apache.jasper.JspC.execute(
Caused by: java.lang.NullPointerException
... 7 more

I tired many solution like to upgrade GAE SDK to 1.8 and re-installed Java 6 in different folder and change some script into appcfg.cmd, BUT did not worked.

Then I changed my laptop path variable and kept my jdk path before C:\Windows\system32.
So, simply I went to start -> Computer -> Right Click -> Properties - > Advanced System Settings ->
Environment Variable  -> Inside System Variable -> click on Path variable -> Click on Edit button -> Add these path (as per you system) C:\Java\jdk1.6.0_39\bin; at first. -> ok.
Restart Eclipse then try to deploy your code to Google.

Second thing, copy tools.jar from your java JDK (in my caseC:\Java\jdk1.6.0_39\lib\tools.jar) to your Apps Engine SDK (E:\Software\Google_Apps_Engine\appengine-java-sdk-1.8.0\appengine-java-sdk-1.8.0\lib\shared)

Other possible Solution:
There could be any real compilation issue in your JSP file, but while trying to build your project into google apps engine, problem would be show there, then follow these steps to know what exactly issue there:

run \bin\appcfg.cmd update  in a command window, it will provide you with a more detailed output then the plugin does and will most likely enable you to resolve the problem in a matter of minutes.

For Example:
E:\Software\NOC\Eclipse-Juno\eclipse\plugins\\appengine-java-sdk-\bin>appcfg.cmd update "E:\Binod\Demo\demogaeprojectWorkspace\LIC\war"

Dear Friend,
You can add your feedback if your problem solved by any other way.

Thursday, April 18, 2013

Ext JS getting start Ext JS first tutorial First Program for EXT JS

Please visit Ext JS site for more information and licence policy on

Ext js tutorial:

1. Download Ext js: and download
2. Unzip it some where
3. Create one dynamic J2ee Project in Exlipse say demoExt and add one server
4. Now inside demoExt Project, create one folder inside the WebContent (demoExt\WebContent\extjs)
5. From unzip of copy adapter, resources folder and ext-all.js and paste inside demoExt\WebContent\extjs
6. Create one jsp (index.jsp) inside the WebContent

contect of index.jsp

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Binod Here</title>

<meta charset=utf-8 />
  <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="extjs/ext-all.js"></script>

<script type="text/javascript" >
    Ext.BLANK_IMAGE_URL = 'extjs/resources/images/default/s.gif';

<script type="text/javascript">

Ext.Msg.alert("Binod","This is Ext alert message");


<h4> Hi Binod from EXT JS</h4>
<%= new java.util.Date() %>

Now deploy this demoExt project in any webserver (inside Eclipse better) and hit the browser with below URL


Now you will see one Ext JS alert box with message "This is Ext alert message".

Happy Ext JS coding ................ :)

That it ............