Friday 12 August 2016

Creating Liferay JSP hook with Liferay 7

Creating Liferay JSP hook with Liferay 7
Liferay 7 doesnt support the hook, as all of the bundles are generated using the OSGI. In OSGI you need to create a fragment and attach the same with the Orginal module. By this we can chnage the existing JSPs in the module.
Liferay IDE as of now doesnt supooort the direct creation of the hook.  So we need to create the hook project using blade and then we can go ahead and do rest of the stuff using the IDE.
Also point to keep in mind is that Liferay 7 GA2 is having a bug due to which theJSP hooks are not getting deployed in the liferay. For further information on that you can go ahead and have a look on this issue https://issues.liferay.com/browse/LPS-66814.
So in this tutorial we will be using the Liferay 7 GA 1.
Following is the command to create a blank project for JSP hook
blade create -t fragment -h <HOST_BUNDLE_SYMBOLIC_NAME> -H <HOST_BUNDLE_VERSION> <PROJECT_NAME>
HOW TO CREATE JSP HOOK IN LIFERAY 7 USING FRAGMENTS TEMPLATE
Step 1 -> Find the value for -h i.e the Host bundle Symbolic name. Open the GOGO shell  as in the below figure
And type lb
This will list down all of the modules/bundles running in that particular server. As we are working on the login jsp hook. we can find the login modules by writing the following command
lb | grep Login

Here the list of all of the Login modules. Now we are interested in the Login Web module.  Modules are listed in the following fashion
BUNDLE_ID | STATUS  |LEVEL |NAME (VERSION)
We can see that Lifeary Login Bundle with Bundle ID 371 is active and is of version (1.0.3).
So now we need to find out the  HOST_BUNDLE_SYMBOLIC_NAME and the HOST_BUNDLE_VERSION in order to create a fragment.
We can get the further details of the bundle by using the command b <BUNDLE_ID>
so we will punch in b 371 this will give us the complete details of the bundle.
We can see that first line is com.liferay.login.web_1.0.3[371], this will give the desired result that we are seeking.
com.liferay.login.web -> HOST_BUNDLE_SYMBOLIC_NAME
1.0.3 -> HOST_BUNDLE_VERSION
So now we are having all of the required details so that we can create a JSP hook for login portlet.
Goto the workspace's module folder  that you have created and punch in the following command.
F:\LR7\wokspace\FirstWorkspace\modules>blade create -t fragment -h com.liferay.login.web -H 1.0.3 my-login-jsp-hook

This will create a blank project in the module folder.
Now we need to copy down the JSPs from the login module which we want to change. To do that import the source  of liferay into eclipse and go to the
/portal-master/modules/apps/foundation/login/login-web/src/main/resources/META-INF/resources
Now copy down the required jsps and paste them into the project that we had just created.
So the result will be something like this

Now customize the changes in the login.jsp  and post that deploy the project


Once deployed you can see that the changes are reflected in the portal as shown below


For more details on the above topic please go through the below video on my youtube channel.

RELATED POSTS

j\

10 comments:

  1. And how can I localize the strings? I would like to add some new fields with localized labels

    ReplyDelete
    Replies
    1. Hi There,

      You can create a new Language file in the /YOUR_PROJECT/src/main/resources/content/Language_es.properties and give the required label. Make sure that the properties file is in the following format Language_LOCALE.properties.
      Pretty shortly I would be writing a blog on this.
      Let me know if you still face a problem.
      Thanks

      Delete
  2. Well, I tried to do what you've suggest inside my fragment project, but unfortunatelly doesn't work. Moreover, there are some incomplete tutorials around, which suggest that I should create a module (what kind of?) which would contain a Java class extending ResourceLoader, and then in @Component description I should specify bundle-name, service context name and so on).
    I am trying to extend the create_account.jsp, so I have to add some keys, but the above mentioned method doesn;t work since com.liferay.login.web has no service context name at all...

    ReplyDelete
  3. Hey as mentioned in the tutorial can you make sure that you are not on GA2.

    ReplyDelete
  4. I can confirm, that hook works on GA3 as well: I use to clean, build, and deploy. If you want to see differences, however, you will have to deploy the .jar file manually. Just take that file and drop onto deploy folder.

    ReplyDelete
  5. Now we need to copy down the JSPs from the login module which we want to change. To do that import the source of liferay into eclipse and go to the
    /portal-master/modules/apps/foundation/login/login-web/src/main/resources/META-INF/resources

    i can't understand this step please help me!!!

    ReplyDelete
    Replies
    1. You need to have the portal sources imported into your Eclipse. The jsp files you are looking for are in the path you have mentioned, but only if you have the sources available.

      You create a blade fragment module as described, and copy the jsp-s from portal-master to your module's /src/main/resources/META-INF/resources

      Delete
  6. how to remove jsp hook from liferay 7. I tried to delete it on the the UI and I also executed on the gogo shell: uninstall .and also remove restarted the server also remove jar from osgi module, but it's still working.

    ReplyDelete
  7. Manoj I am getting same error. If you found the solution please email to me at harshkanakhara@gmail.com

    ReplyDelete
  8. hello every one,am trying to override custom jsp in hook in liferay7,but am facing problemn in action class,mean its not hitting if any one got solution pls send the code to this mail(meelas.saleem.71@gmail.com)

    ReplyDelete

 

Copyright @ 2016 LiferayRevisited.