How does liferay list out the portlet to be shown in the control panel menu?
Can any body list the classes and JSP involved in the same?
Refer to file in your liferay source at location : \portal-web\docroot\html\portlet\control_panel_menu\view.jsp
You will get idea how liferay shows its control panel menu.
Link for code of this jsp.
All of the portlets are saved in the portlet table while we deploy them. Then once the control panel is accessed then liferay loads all of the portlet which are having the control panel entry in them. For better explanation see the below code in
com.liferay.portal.util.PortalImpl
#Override
public Set<Portlet> getControlPanelPortlets(long companyId, String category)
throws SystemException {
Set<Portlet> portletsSet = new TreeSet<Portlet>(
new PortletControlPanelWeightComparator());
if (Validator.isNull(category)) {
return portletsSet;
}
List<Portlet> portletsList = PortletLocalServiceUtil.getPortlets(
companyId);
for (Portlet portlet : portletsList) {
String portletCategory = portlet.getControlPanelEntryCategory();
if (category.equals(portletCategory) ||
(category.endsWith(StringPool.PERIOD) &&
StringUtil.startsWith(portletCategory, category))) {
portletsSet.add(portlet);
}
}
return portletsSet;
}
#Override
public List<Portlet> getControlPanelPortlets(
String category, ThemeDisplay themeDisplay)
throws SystemException {
Set<Portlet> portlets = getControlPanelPortlets(
themeDisplay.getCompanyId(), category);
return filterControlPanelPortlets(portlets, themeDisplay);
}
The above code is called from the
\portal-web\docroot\html\portlet\control_panel_menu\view.jsp
Map<String, List<Portlet>> siteAdministrationCategoriesMap = PortalUtil.getSiteAdministrationCategoriesMap(request);
Help taken from pankaj-kathiriya answer. Thanks for the same.
Related
I use Orchard CMS 1.10.1. I have created a content type, now I want to have a section menu in admin page to have specific links for this content type. I want it include New link and content item list for this content type.
How can i achieve this? preferably with no editing in the code.
You can't do this without code, at the same time you will need a small code chunk to achieve this, like the following code:
public class AdminMenu : INavigationProvider {
public Localizer T { get; set; }
public string MenuName {
get { return "admin"; }
}
public void GetNavigation(NavigationBuilder builder) {
builder
.Add(T("Your Content Type Display Name"), "1", menu => menu
.Action("List", "Admin", new { area = "Contents", id = "YourContentTypeName" }));
}
}
I was attending an interview last week and interviewer asked me, how you add a portlet in liferay?
I just replied, while creating a plugin project in eclipse a option appears Add to control panel that is the way i use to add portlet in control panel.
and he asked again when you do that what liferay does initially and i was like unanswered.
can any one please explain it?
All of the portlets are saved in the portlet table while we deploy them. Then once the control panel is accessed then liferay loads all of the portlet which are having the control panel entry in them. For better explanation see the below code in
com.liferay.portal.util.PortalImpl
#Override
public Set<Portlet> getControlPanelPortlets(long companyId, String category)
throws SystemException {
Set<Portlet> portletsSet = new TreeSet<Portlet>(
new PortletControlPanelWeightComparator());
if (Validator.isNull(category)) {
return portletsSet;
}
List<Portlet> portletsList = PortletLocalServiceUtil.getPortlets(
companyId);
for (Portlet portlet : portletsList) {
String portletCategory = portlet.getControlPanelEntryCategory();
if (category.equals(portletCategory) ||
(category.endsWith(StringPool.PERIOD) &&
StringUtil.startsWith(portletCategory, category))) {
portletsSet.add(portlet);
}
}
return portletsSet;
}
#Override
public List<Portlet> getControlPanelPortlets(
String category, ThemeDisplay themeDisplay)
throws SystemException {
Set<Portlet> portlets = getControlPanelPortlets(
themeDisplay.getCompanyId(), category);
return filterControlPanelPortlets(portlets, themeDisplay);
}
The above code is called from the
\portal-web\docroot\html\portlet\control_panel_menu\view.jsp
Map<String, List<Portlet>> siteAdministrationCategoriesMap = PortalUtil.getSiteAdministrationCategoriesMap(request);
Experts pl correct me if I am wrong.
i'm trying to set portlet preferences, without touch the portlet.xml.
Here is my portlet :
-myportletclass
-myportletjsp
-myconclass
-myconfjsp
When I click on preferences, I can see the confjsp, wich display a form for my preferences. And, when I submit it, set the preferences to the values in the form.
But I don't have any default values, without modify the portlet.xml.
What shoul I add and where?
I saw some do it in the render of the config class, but it doesn't work their way.
Regards.
Thank you.
edit : the way i set my preferences :
first, i have a simple form i my conf jsp, basic, no need to add it;
Then, i have the ConfController :
#Controller
#RequestMapping("EDIT")
public class ConfigurationController {
#ModelAttribute("validatePref")
public ValidatePrefForm getValidatePrefForm() {
ValidatePrefForm form = new ValidatePrefForm();
return form;
}
#ActionMapping(params = "action=validatePref")
public void processAction(#ModelAttribute("validatePref") ValidatePrefForm form,
PortletPreferences portletPreferences, ActionResponse response)
throws Exception {
String mylink = form.getMylink();
if (null != mylink && !mylink .equals("")) {
portletPreferences.setValue("mylink ", mylink );
}
portletPreferences.store();
}
#RenderMapping
public String render() throws Exception {
return "myportletjsp.jsp";
}
}
And then, in my portlet i have this to get the value:
mylink= preferences.getValue("mylink", mylink);
if(null==mylink){
mylink= mydefaultUrl;
}
And then i can use mylink
First of all: portlet.xml is an excellent place to have default portlet preferences.
If you absolutely don't want this for some reason, of course you can check if the preference is null, then assume your defaults. Simply do this whereever you retrieve the portlet preferences - in the action-, render-, event- or resource-phase.
We have something called nested portlets in liferay. I want to add this portlet dynamically through code. Does anyone know the code for adding nested portlets, and add other portlets inside it?
Thanks !!!
for complete example i'll assume that you want to add nested portlet to current page using another portlets action handler. (if used from render action you would not see nested portlet until next view of the page)
Add these methods to your code
private static String addPortlet(final long p_userId, final Layout p_layout, final String p_portletId, final String p_columnId, final int p_position, final boolean p_checkPermission)
throws PortalException, SystemException
{
if (p_layout.isTypePortlet()) {
final LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) p_layout.getLayoutType();
final String portletId = layoutTypePortlet.addPortletId(p_userId, p_portletId, p_columnId, p_position, p_checkPermission);
if (portletId != null) {
final String rootPortletId = PortletConstants.getRootPortletId(portletId);
final String portletPrimaryKey = PortletPermissionUtil.getPrimaryKey(p_layout.getPlid(), portletId);
ResourceLocalServiceUtil.addResources(p_layout.getCompanyId(), p_layout.getGroupId(), 0, rootPortletId, portletPrimaryKey, true, true, true);
LayoutLocalServiceUtil.updateLayout(p_layout.getGroupId(), p_layout.isPrivateLayout(), p_layout.getLayoutId(), p_layout.getTypeSettings());
}
return portletId;
}
return null;
}
private static void addNestedPortlet(final PortletRequest p_request) throws PortalException, SystemException {
final ThemeDisplay themeDisplay = (ThemeDisplay) p_request.getAttribute(WebKeys.THEME_DISPLAY);
final Layout layout = themeDisplay.getLayout();
long userId = themeDisplay.getUserId();
//create nested portlet and add it to "column-1"
final String nestedPortletId = addPortlet(userId, layout, "118", "column-1", -1, false);
//this will be used to target nested portlet's columns
final String nestedColumnPrefix = "_" + nestedPortletId + "__";
//default page layout (used by nested portlet) has two columns
//we'll add two portlets (in this example two iframe portlets), one portlet to each column
addPortlet(userId, layout, "48", nestedColumnPrefix + "column-1", -1, false);
addPortlet(userId, layout, "48", nestedColumnPrefix + "column-2", -1, false);
}
If you would like, and probably you would, to add nested portlet to another page or not from portlet, you can lookup Layout and User instead of getting them from ThemeDisplay.
I'm trying to create a custom property for my web part, but can't get it to show up in Sharepoint. Here's my current code :
[Serializable]
[XmlRoot(Namespace = "MyWebPart")]
[DefaultProperty("Text")]
public class MyWebPart : WebPart
{
...
[Category("My Web Parts Properties")]
[DefaultValue(defaultPropertyValue)]
[WebPartStorage(Storage.Shared)]
[FriendlyNameAttribute("Property name")]
[Description("Longer desc for my property")]
[Browsable(true)]
[XmlElement(ElementName = "SomeProperty")]
public string SomeProperty
{
get { return someProperty; }
set { someProperty = value; }
}
Is there something else required to get custom properties working?
I think you're using the wrong properties
SO - Sharepoint custom web part property does not show up in the toolbox