Make liferay portlet non instanceable - liferay

How can I make my portlet non instanceable accross the liferay instance. I have read about it in the forum but there was no mention of how to do it.

You can specify a portlet as non instanceable by putting
<liferay-portlet-app>
...
<portlet>
...
<instanceable>false</instanceable>
...
</portlet>
...
</liferay-portlet-app>
in the file
liferay-portlet.xml
Beware of the right order of tags, according to the dtd (linked the dtd version 5.2, shouldn't have changed much though)
Also have a look here
Liferay docu

Related

Accessing an action from a portlet from another

So I have an action in a portlet "pA" that prints some info based on the logged user, and now I need that info in another portlet "pB". Instead of duplicating the code, I want to access the action of porlet "pA" from "pB". Is that even possible?
Researching I've managed to get to this at the beginning of "pB":
<%# taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<liferay-portlet:actionURL var="name" portletName="pA_WAR_war-of-pA">
<liferay-portlet:param name="view" value="v" />
</liferay-portlet:actionURL>
<h1>URL:: ${name}</h1>
But it generates an url for "pB" instead of "pA" ???
I wouldn't worry so much if this is possible, because it's bad style. If you need the same code in two different portlets, just provide it in a library and use that from both portlets.
A portlet, on the UI layer, should be a closed concept and not have interdependencies with other portlets. A dependency on a common library however is fine.

message always shown in the same language instead of configuring the browser not to

I am trying to show a welcoming message in a JSF page in different languages (English or Spanish) depending on the user's browser configuration.
These are the steps I follow:
1-In Netbeans I create a WAR project
2-In the folder Source Packages I create a package named locale, and inside that package, I create 2 files (messages.properties, messages_es.properties)
messages.properties
greeting = Welcome!
messages_es.properties
greeting = Bienvenido!
3-In the folder Web Pages I create the file index.html
<h:outputText value="#{msg['greeting']}" />
4-In faces-config.xml I write this code:
<locale-config>
<default-locale>en</default-locale>
<supported-locale>es</supported-locale>
</locale-config>
<resource-bundle>
<base-name>locale.messages</base-name>
<var>msg</var>
</resource-bundle>
When I run the application in my browser always is shown the welcoming message in Spanish (BIenvenido!), also when I change the preference order (Preferences-Content-Language) to show the web page in English.
What am I doing wrong?
I finally managed to find the error. I changed the messages.properties file name to messages_en.properties and it works well.

Add a global Jsp to include in Liferay tomcat-6

I have a Jsp that dynamically needs to get included in entire project as user opens any jsp. i.e. As a user opens a jsp my jsp should automatically gets included.
I have written this in web.xml in Tomcat
<jsp-property-group>
<url-pattern>/webapps/ROOT/html/*.jsp</url-pattern>
<url-pattern>*.jspf</url-pattern>
<el-ignored>false</el-ignored>
<scripting-invalid>false</scripting-invalid>
<is-xml>false</is-xml>
<include-prelude>/WEB-INF/jsp/tracker.jsp</include-prelude>
<!-- <include-coda>/template/coda.jspf</include-coda> -->
</jsp-property-group>
I had kept my jsp in tomcat under WEB-INF/jsp/ and i want to include it into every porject as it contains a code that tracks log for user.
Or any other way to make this happen.
Thanks.
There is one more way to include your JSP for the whole portal and i.e. the dockbar.
You can create a hook and include your jsp in the /html/portlet/dockbar/view.jsp using either <jsp:include /> or <liferay-util:include /> or simple <%# include file="" /> (this would be static).
<jsp:include page="/jsp/yourJSPPageToBeIncluded.jsp" />
OR
<liferay-util:include page="/jsp/yourJSPPageToBeIncluded.jsp" />
OR
<%# include file="/jsp/yourJSPPageToBeIncluded.jsp" />
Note: the path may differ depending on where you will be putting the JSP.
Why I am choosing dockbar is because it is present on all the portal-pages of liferay. This won't work if you are opening a pop-up like configuration pop-up or look-and-feel pop-up or other custom dialog pop-ups since dockbar is not present in the pop-up. For using in pop-ups you would have to override portal_pop_up.vm in your custom-theme and write the code as suggested by #VikasV
$theme.include($themeServletContext, "/jsp/yourJSPPageToBeIncluded.jsp")
There are two ways for this.
Simple way is to include your JSP in the Theme. When your Theme is applied to your project, and when Theme is rendered, any pages in your project will render this included JSP.
Code sample below. This has to be placed in vm file(navigation.vm).
$theme.include($themeServletContext, "/jsp/yourJSPPageToBeIncluded.jsp")
Here, JSP folder is placed directly inside Theme war.
Other way (tedious one), is to include this JSP in each and every JSP page that you want this to be included.
Use <jsp:include> element for this.
Some references,
Ref1
Ref2

How to add custom portlet in Control Panel section

How can I add a custom portlet to the Portal section of the Control Panel, as shown in the following figure:
Here is how to do it:
In your portlet's liferay-portlet.xml (you can check the DTD of this xml for more information on other tags) include two tags in your <portlet> tag as shown:
<portlet>
<portlet-name>MyCustomPortlet</portlet-name>
<icon>/mycustom.png</icon>
<!--
These are the two entries which are required for the portlet
to appear in the control panel
-->
<!--
Set the control-panel-entry-category value to "my", "content",
"portal" or "server" to make this portlet available in the
Control Panel under that category.
-->
<control-panel-entry-category>portal</control-panel-entry-category>
<!--
Set the control-panel-entry-weight value to a double number
to control the position of the entry within its Control Panel
category. Higher values mean that the entry will appear lower
in the Control Panel menu.
-->
<control-panel-entry-weight>100</control-panel-entry-weight>
<instanceable>false</instanceable>
<header-portlet-css>/css/main.css</header-portlet-css>
<footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
<css-class-wrapper>mycustomportlet-portlet</css-class-wrapper>
</portlet>
Also, if you don't want your portlet to appear in the Add Menu so that it is not put on other pages, then in your liferay-display.xml you can include:
<display>
<category name="category.hidden">
<!--
Adding your portlet to the hidden category would not display
the portlet in the ADD Menu on the top-left-hand corner
-->
<portlet id="MyCustomPortlet"></portlet>
</category>
</display>
Build and deploy your portlet and you are good to go.
Apart from the Answer by Prakash K, ajaxable and instanciable should be false.

Invisible comments in jsf 2.0? [duplicate]

This question already has an answer here:
How can I remove HTML comments in my Facelets?
(1 answer)
Closed 8 years ago.
is it possible to embed comments in my .xhtml-files that are only displayed in the source and not the rendered result?
I want to include author, date,... in the files but they should not be visible to the enduser in the generated output. If I use the standard comment-tags <!-- --> the browser displays them.
Add the following into your web.xml:
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
This way Facelets will skip the comments while parsing the view xhtml template.
Invisible comments in JSF is a drawback, specially for beginers. I agree with answer of Mr Minchev. Anyway, I provide an alternative way to comment content in JSF consisting of using ui:remove
<ui:remove> This is a comment </ui:remove>
The UI Remove tag is used to specify tags or blocks of content that should be removed from your page by the Facelets view handler at compile time. This tag has no attributes. You can use this tag to indicate that a particular tag should be removed from the rendered page.
It's useful to remove content which is required during design time, but not during run time, such as comments, some stubbed content (e.g. "lorem ipsum") which aids in filling up the page content to fit the layout in visual designers such as Dreamweaver, etc.
See: Practical implications of Facelets ui:remove tag
Note that the Facelets compilation process is much faster than the JSP compilation process because no Java bytecode is actually generated and compiled behind the scenes when you first visit your page. The UI Remove tag is used to specify tags or blocks of content that should be removed from your page by the Facelets view handler at compile time. This tag has no attributes.
Examples of both comment options
Wrong, the right way is:
<context-param>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</param-value>
This work for me, javax.faces.FACELETS_SKIP_COMMENTS no!

Resources