掲示板

Customize the Control Menu

6年前 に Rahul Joshi によって更新されました。

Customize the Control Menu

Junior Member 投稿: 63 参加年月日: 17/03/03 最新の投稿
I am using Liferay DXP version and want to customize the Control Menu. I cannot find it in the theme files. Any idea how this can be done?
Basically I want an image to show in that.
6年前 に Rahul Joshi によって更新されました。

RE: Customize the Control Menu

Junior Member 投稿: 63 参加年月日: 17/03/03 最新の投稿
Rahul Joshi:
I am using Liferay DXP version and want to customize the Control Menu. I cannot find it in the theme files. Any idea how this can be done?
Basically I want an image to show in that.


Any help on this?
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: Customize the Control Menu

Liferay Legend 投稿: 6396 参加年月日: 08/09/23 最新の投稿
Rahul Joshi:
I am using Liferay DXP version and want to customize the Control Menu. I cannot find it in the theme files. Any idea how this can be done?
Basically I want an image to show in that.


If you need to know which CSS class to target: Use your browser's Developer Tools (aka Firebug). For behavioral changes the documentation might help
6年前 に Rahul Joshi によって更新されました。

RE: Customize the Control Menu

Junior Member 投稿: 63 参加年月日: 17/03/03 最新の投稿
Thanks. So I assume if I need to add a something to the control menu, the link you provided shall suffice.
6年前 に Rahul Joshi によって更新されました。

RE: Customize the Control Menu

Junior Member 投稿: 63 参加年月日: 17/03/03 最新の投稿
I have followed the link to customise the control menu. But it teaches how to add Lexicon or Font Awesome Icons in the TOOLS area. I want to add a custom image in that place instead of pre-supplied icons.
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: Customize the Control Menu

Liferay Legend 投稿: 6396 参加年月日: 08/09/23 最新の投稿
Rahul Joshi:
I have followed the link to customise the control menu. But it teaches how to add Lexicon or Font Awesome Icons in the TOOLS area. I want to add a custom image in that place instead of pre-supplied icons.


To me it looks like Item 4 on that page describes exactly that (granted, not to the point, but it gives the hints):

Implement the ProductNavigationControlMenuEntry interface. You can also extend the BaseProductNavigationControlMenuEntry or BaseJSPProductNavigationControlMenuEntry abstract classes. Typically, the BaseProductNavigationControlMenuEntry is extended for basic entries (e.g., IndexingProductNavigationControlMenuEntry) that only display a link with text or a simple icon. If you’d like to provide a more complex UI, like buttons or a sub-menu, you can do so by overriding the include() and includeBody() methods. If you are going to use JSPs for generating the UI, you can extend BaseJSPProductNavigationControlMenuEntry to save time. This will be elaborated on more extensively in the next step.
6年前 に Rahul Joshi によって更新されました。

RE: Customize the Control Menu

Junior Member 投稿: 63 参加年月日: 17/03/03 最新の投稿
Olaf Kock:

To me it looks like Item 4 on that page describes exactly that (granted, not to the point, but it gives the hints):
Implement the ProductNavigationControlMenuEntry interface. You can also extend the BaseProductNavigationControlMenuEntry or BaseJSPProductNavigationControlMenuEntry abstract classes. Typically, the BaseProductNavigationControlMenuEntry is extended for basic entries (e.g., IndexingProductNavigationControlMenuEntry) that only display a link with text or a simple icon. If you’d like to provide a more complex UI, like buttons or a sub-menu, you can do so by overriding the include() and includeBody() methods. If you are going to use JSPs for generating the UI, you can extend BaseJSPProductNavigationControlMenuEntry to save time. This will be elaborated on more extensively in the next step.


I have been trying this now. But it is having difficulty locating the jsp that has custom code. It always says file not found. I have updated the bnd.bnd file as well.
6年前 に Rahul Joshi によって更新されました。

RE: Customize the Control Menu

Junior Member 投稿: 63 参加年月日: 17/03/03 最新の投稿
More details:
Attached the Java class I am working on.
Attached the bnd.bnd file that I am using.

Error in console:

ERROR [http-nio-8080-exec-10][IncludeTag:128] Current URL /web/guest generates exception: java.lang.NullPointerException
java.lang.NullPointerException
	at com.liferay.product.navigation.control.menu.BaseJSPProductNavigationControlMenuEntry.include(BaseJSPProductNavigationControlMenuEntry.java:84)
	at com.liferay.product.navigation.control.menu.BaseJSPProductNavigationControlMenuEntry.includeIcon(BaseJSPProductNavigationControlMenuEntry.java:68)
	at org.apache.jsp.control_005fmen.....
thumbnail
6年前 に Julio Camarero によって更新されました。

RE: Customize the Control Menu

Liferay Legend 投稿: 1668 参加年月日: 08/07/15 最新の投稿
Hi Raul,

the Nullpointer in that exception seems to point that your ServletContext (the context from where you serve the jsp) is null.

You should do the following things:
- Implement the method getIconJspPath() to return the path to your jsp file in your module. (the same module where your class is located). The path starts looking from: your-module-folder/src/main/resources/

e.g. If you have the jsp: your-module-folder/src/main/resources/my-file.jsp, then your method would be like this:

@Override
public String getIconJspPath() {
return "my-file.jsp";
}

- Implement the method setServletContext passing the reference to your module:
@Override
@Reference(
target = "(osgi.web.symbolicname=simbolic.name.of.your.module)",
unbind = "-"
)
public void setServletContext(ServletContext servletContext) {
super.setServletContext(servletContext);
}

Where simbolic.name.of.your.module is defined in the bnd.bnd file, in your example that would be: CustomProductNavigationControlMenuEntry

In order to have a servlet context, your module should also define a web context path in your bnd (you are already doing this), such as:
Web-ContextPath: /web-context-for-my-module

You can also use the blade tools to automatically generate a working example for you. In the link that Olaf provided above, there is a section explaining how to configure the blade tools to do this. You can also look at the source code of the blade examples if you prefer to just have a quick look.


Some details from your file:
- You have some properties from the portlet service (javax.portlet....) that will be ignored by this type of service.
- Don't override the includeIcon/includeBody methods unless you really need to. (you shouldn't need it for your example, you only need to implement getIconJspPath and/or getBodyJspPath)


Cheers!
6年前 に Rahul Joshi によって更新されました。

RE: Customize the Control Menu

Junior Member 投稿: 63 参加年月日: 17/03/03 最新の投稿
Thanks for the detailed response Julio. Let me try with all these steps in mind.
6年前 に Rahul Joshi によって更新されました。

RE: Customize the Control Menu

Junior Member 投稿: 63 参加年月日: 17/03/03 最新の投稿
Hi Julio,

I am not getting any error now but the JSP is not getting rendered. Code in my Java Class is as follows:

@Override
 @Reference(
     target = "(osgi.web.symbolicname=CustomProductNavigationControlMenuEntry)",
     unbind = "-"
 )
 public void setServletContext(ServletContext servletContext) {
  
     super.setServletContext(servletContext);
 
 }

 @Override
 public String getIconJspPath() {
  // TODO Auto-generated method stub
  return "control_menu.jsp";
 }


Additionally, the folder structure and bnd.bnd file details are in the attached image.