RE: Creating Control Panel Entry in a portlet

Daniel G, modified 6 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
Hi everyone.
I am trying to develop a portlet which has an configuration entry in the control panel but I am not able to do it. I am using Liferay 7.1
I have added a class which extends BasePanelApp
@Component(
        immediate = true,
        property = {
            "panel.app.order:Integer=1",   // Defines position in list
           "panel.category.key=" + PanelCategoryKeys.CONTROL_PANEL_CONFIGURATION, 
        },
        service = PanelApp.class
    )
public class AdminDirectoryDXP  extends  BaseJSPPanelApp {    @Override
    public String getPortletId() {
        return DirectoryDXPportletPortletKeys.portlet;    // Same name of the portlet.
    }    @Override
     @Reference(target = "(javax.portlet.name=" + DirectoryDXPportletPortletKeys.portlet + ")",unbind = "-")
    public void setPortlet(Portlet portlet) {
        super.setPortlet(portlet);
    }
  
}

When I deploy the portlet, I see the option but when I press it it goes to no page. I tried to change the class and override BaseJSPPanelApp and adding the method:
    @Override
    public String getJspPath() {
        // TODO Auto-generated method stub
        return "/view.jsp";
    }    

but it doesnt work. Anyone has done it and can help me with this? Any help would be very appreciated because I'm running out of ideas.
Thanks in advance.
Kind regards.
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hey Daniel, I'm using this approach all over the place in multiple solutions. I've even gone as far as making my own buckets that settings live under -- so for sure it works. Can you share the other classes with us? (the portlet, the portletkeys, etc)
Daniel G, modified 6 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
First of all, thanks for your help. I have a very basic portlet, only with the definitions.

Jsp files are in resources folder and are empty, I attach the java files.
Thanks again!
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Ok cool -- I'll put this into a module on my side and report back what happens. It's pretty late for me though, so I'm gonna do it in the morning. 
Daniel G, modified 6 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
Thanks so much Andrew.
Regards
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hey Daniel,
Sorry man -- the day totally got away from me. I launch a new site today and anticipated having to do less. Anyway, I've created a sample project on my side and looked at your classes and then tweaked my own accordingly. I've attached the project here for you to reference. It is working for me and I am willing to bet it is working for you, but perhaps it looks like it isn't working because you are expecting to find your control panel portlet in a location where it is not.  Here is what I did.

Step #1: Created panel app module 

$>blade create -t panel-app -v 7.1 -p  com.jardineworks.directorydxp dxp-directory-admin


That gave me the baseline module to work with. I started by modifying the portlet keys to include a name that is the canonical name for the portlet, replacing the periods with underscores. You don't HAVE to do this, it's just a pattern that I follow because, well, it's what Liferay does. I looked at your constant, and the value is fine. I checked it because I have had scenarios in the past where I foolishly used an actual canonical name (com.jardineworks.something.SomePortlet) instead of the modified version (com_jardineworks_something_SomePortlet) and if you use the dots -- she don't work.

Step #2: I just made a few updates to the references to the portlet keys, but basically left everything else the same

Step #3: deployed my plugin to the server

Step #4: Logged in and went to the control panel

Now there are two main services that go into the positioning, both are in the application.list package (if you use the blade template to generate). The first is the XXXPanelApp, the second is the XXXPanelCategory.The XXXPanelCategory is WHERE in the control panel you want to place your portlet -- think of this as the big bucket container. The -v 7.1 blade template generates the module such that, if unaltered, You'll find it in the Site Administration section -- position 100 puts it in the first slot, above the "Build" section where you mange pages and menus for the current site.  If you want it somewhere else, then in this XXXPanelCategory class you need to change the osgi property for the panel.category.key to a different value. Now the kind of confusin part. The getKey() method, by default (as in generated from the template) does a  

return DxpDirectoryAdminPanelCategoryKeys.CONTROL_PANEL_CATEGORY;

Not that constant on the end can be a little confusing because, at a glance, it looks like it should be under the "Control Panel" section. In actuality, that is a reference to a constant from the constants package, XXXPanelCategoryKeys, which is a reference to the language.properties entry 

javax.portlet.title.com_jardineworks_directorydxp_DxpDirectoryAdminPortlet=DxpDirectoryAdmin

So what happens is, You have a new entry in the first position of the Site Administration section, then it's actually a section you can open, and in there you would find a link called DxpDirectoryAdmin, and clicking that link, renders your portlet. Now what about the BasePanelApp? .. or rather the XXXPanelApp -- well, that ties it altogether by mapping the PanelCategoryKey and then being the provider of the portlet to be rendered. 

I know it's a bit to get your head around but there is some really cool stuff you can do. For some of my clients that have all sorts of configurations and things that they want to use to manage their applications, I will create a top level section with the client or app name. Then I can create a bunch of panel apps and file them all under that company/appname category. That way, when they need to make a change, the go into the Control Panel, go to, say Site Administration > Company XYZ, then click through the links (Dashboard, Audit, Search, etc) to view/edit whatever app settings they need. So once you get the hang of it, it's a pretty neat feature that is super pluggable and can create some pretty awesome "wow factor". Anyway, project attached.

Hope this helps. Let me know if you have any other questions. 
Daniel G, modified 6 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
wow, thanks a lot for your help. I really appreciate it!
My doubt now is:  I can see the action in panel entry. When I press the new entry, it brings me to a empty page like this:

How can I edit that page? Or redirect the panel entry to the page that I want? I am not able to find a way to do it.
Thanks in advance again!Regards.
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Daniel,
I'm not sure I am totally following. In the example I sent over, there is a view.jsp and that is what is loaded (like any other portlet/widget) when you click on the link from the left hand control panel navigation.  outside of the PanelApp and PanelCatergory, you would code this solution the same way you would any other portlet that you would drop onto a page in the site -- adding the JSPs, actions, etc in the project and setting dependencies on other modules to leverage their internals as needed. 
Are you able to send me your entire module zipped up so that I can try it in my environment?
Daniel G, modified 6 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
I've deployed your zip, without changing anything, and when I press the entry of control panel it brings me to the page that I am shown in the image of my last post, it does not shows me  the view.jsp
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
That can't be right at all. In the screenshot above I can see in the URL above that the p_p_id (the portlet id) is ProductAdmin. In the project file I sent over, the p_p_id should match the value from the PortletKeys file -- which you can see from my screenshot.  Can you send me a screenshot of the whole screen with the control panel menu (on the left) open? Does it look like mine?
Daniel G, modified 6 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
Andrew, I was downloaded some examples and I took another one thinking that it was your module! I took the right one now and I've deployed it and it works!Thanks so much, now I can see where I had done wrong in my tests.Thank so so much for your help and for your time!
Regards
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Phew! I was really confused for a minute there hahah ... gad to hear you got it all worked out. Let us know if you need anything else!