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.
Related
I've found that when changing an included file, if I use the include action tag, then the change is reflected in the including jsp. But if I use the include directive, then the the change is not reflected in the including jsp.
However, I've found that the change does get reflected in the including jsp whether we use include action tag or include directive.
Please show me the difference using a program.
The contents of the directives form part of the main JSP during the translation phase, ie., when the JSP is compiled in to an equivalent servlet. So the contents from the jsp included using a directive componnet are merged in to the parent jsp at the translation time which happens only once. This include directive was mainly meant to be used for addressing the headers and footers which are mostly static that doesn't get changed often.
The include action tag on the other hand is for including dynamic contents ie., you can choose to send a parameter to the tag which that tag may process and display. this is unlike the headers and footers showing the same content again and again.
Main.jsp
<jsp:include page="included.jsp">
<jsp:param name="message" value="World" />
</jsp:include>
Included.jsp
<html>
<head>
</head>
<body>
<h2>Hello <%=request.getParameter("message") %></h2>
</body>
</html>
Also what server are you using. Since Tomcat7, things have changed and the main jsp will also compile if the included jsp(by any mechanism) is changed.
this link has more details.
Can any one tell me how can I create the back button in my portlet. Are there any existing tags to create the back button which looks like as shared below.
Solution as mentioned in below post should work.
http://www.liferay.com/en_GB/community/forums/-/message_boards/message/22392288
Liferay uses back URL in many of its default portlets.
For example, You can refer sources for message board portlet - view.jsp, edit_category.jsp
If you use to move from first JSP to second JSP, then backURL should be passed as argument in first JSP and retrieve in second JSP to use inside liferay-ui:header tag.
For example,
<portlet:renderURL var="varURL">
<portlet:param name="mvcPath" value="<second-JSP-URL>"></portlet:param>
<portlet:param name="backURL" value="<%= themeDisplay.getURLCurrent() %>"></portlet:param>
</portlet:renderURL>
Try this instead.
Just use one line and it will direct back to previous URL.(Place this code in second jsp).
<input type=button value=" Back" onClick="javascript: window.history.go(-1)" text-align="right">
I work on liferay.We use one module in our project for liferay theme creation. I use command ant -Ddeploy.war=true which deploys it in the server. The war file gets created in the liferay deploy folder. But when I start the server I do not get any options for login. I do not get any liferay specific options. I get the following server logs
An error occurred at line: 117 in the jsp file: /html/portlet/login/login.jsp
com.alepo.hooks.ConcurrentLoginException cannot be resolved to a type
114: <liferay-ui:error exception="<%= UserLockoutException.class %>" message="this-account-has-been-locked" />
115: <liferay-ui:error exception="<%= UserPasswordException.class %>" message="please-enter-a-valid-password" />
116: <liferay-ui:error exception="<%= UserScreenNameException.class %>" message="please-enter-a-valid-screen-name" />
117: <liferay-ui:error exception="<%= com.alepo.hooks.ConcurrentLoginException.class %>" message="max-sessions-exceeded" />
118:
119: <fieldset class="block-labels">
120: <div class="ctrl-holder">
Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:451)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:328)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:307)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:565)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
at com.liferay.taglib.util.IncludeTag.doEndTag(IncludeTag.java:67)
at org.apache.jsp.html.common.themes.portlet_jsp._jspService(portlet_jsp.java:2669)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
Any Idea about it?
It seems your custom login-hook is messed-up and it is not a problem with the theme.
If you read the error carefully:
An error occurred at line: 117 in the jsp file: /html/portlet/login/login.jsp
com.alepo.hooks.ConcurrentLoginException cannot be resolved to a type
So what is happening is the /html/portlet/login/login.jsp is not able to find the class ConcurrentLoginException which probably resides in your hook, why this is happening is because the way liferay handles class-loading.
In short, there are 3 classloaders:
global (the classes in the servers lib like tomcat/ext/lib like database drivers and portal-service.jar): These classes can be used by and is available to all the plugins context and liferay's context.
Portal classloader (classes in ROOT/WEB-INF/lib like the famous portal-impl.jar): These classes or implementation is available only to Liferay's context.
Portlet / Plugin ClassLoader (loads the classes of our plugins): These are available to our plugins (portlets, hooks etc) and is not available to liferay's modules/context.
So after this short crash-course you may have already known what the problem is, but still I would try to answer this (for points sake :-).
So here it is, since a JSP-hook modifies liferay's JSP and is copied over to the ROOT directory it falls under liferay's context so any custom class created inside a plugin (portlet or hook or themes) would not be available to the JSP, so in this case the login.jsp.
So either don't use that class ;-) inside the JSP or put your exception class (packaged in a jar) in the global path i.e. tomcat/ext/lib so that it is available to the login.jsp.
Here is the verdict from Liferay Staff on a similar issue and another answer which might help drive the concept home and help in the future.
Looks like you haven't imported the ConcurrentLoginException class in your /html/portlet/login/login.jsp
Assuming that the ConcurrentLoginException class is in your project, import the class into the login.jsp by placing the below line at the top in login.jsp :
<%#page import="com.alepo.hooks.ConcurrentLoginException"%>
If ConcurrentLoginException class is not present in your project, then use Prakash's method which is an excellent answer on how to map a dependency.
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
I've added the following code to the selected transformation of a News List webpart:
<%# Register Src="~/CMSAdminControls/ContentRating/RatingControl.ascx" TagName="RatingControl" TagPrefix="cms" %>
<cms:RatingControl ID="elemRating" runat="server" Enabled="true" RatingType="Stars" ExternalValue='
<%# Convert.ToString(CMS.GlobalHelper.ValidationHelper.GetDouble(Eval("DocumentRatingValue"), 0)/((CMS.GlobalHelper.ValidationHelper.GetDouble(Eval("DocumentRatings"), 0) == 0?1:CMS.GlobalHelper.ValidationHelper.GetDouble(Eval("DocumentRatings"), 1)))) %>' />
The rest of the selected transformation is the same as the default.
According to the Kentico documentation this should add the webpart to the details page of a news item.
For some reason the input tag is getting rendered as follows:
<input type="hidden" name="p$lt$zoneContent$pageplaceholder$pageplaceholder$lt$News$NewsList$repItems$ctl00$ctl00$elemRating$RatingControl$elemRating_RatingExtender_ClientState" id="p_lt_zoneContent_pageplaceholder_pageplaceholder_lt_News_NewsList_repItems_ctl00_ctl00_elemRating_RatingControl_elemRating_RatingExtender_ClientState" value="0">
note the type="hidden" attribute. This causes the control not to render and I'm not sure where to fix this.
As mentioned in my comment. The is actually just used to store the value. Below that, it renders some extra content that will not display unless some CSS classes are carried over from the CMSDesk.css.
You can either copy the necessary CSS classes into your own CSS, or just import the CMSDesk.css file where necessary to make sure the rating elements are displaying.