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
Related
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.
I've some unique problem, but I think this is not problem, I just want to optimize the url that my website have.
so I want to change all
index.html
on every folder as example
culture
folder, so normally if we want access
index.html
in culture folder we can just type
culture/index.html
right? but i want to access by just type
culture/
Is it possible to do that? If so, how we produce? I'm using jsf 2 as programming language.
Maybe I misunderstand your problem, but this can be done by configuring welcome files in the web.xml file:
Web Application developers can define an ordered list of partial URIs
called welcome files in the Web application deployment descriptor. The
purpose of this mechanism is to allow the deployer to specify an
ordered list of partial URIs for the container to use for appending to
URIs when there is a request for a URI that corresponds to a directory
entry in the WAR not mapped to a Web component. This feature can make
your site easier to use, because the user can type a URL without
giving a specific filename.
Note: Welcome files can be JSPs, static pages, or servlets.
Just:
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
I've tested this on WildFly 11 and it works, my project structure is:
+ WebContent
- index.xhtml
+ folder_a
- index.xhtml
+ folder_b
- index.html
+ folder_c
- other_name.xhtml
- some_name.html
When I enter:
http://localhost:8080/myproject/ I get a content from WebContent/index.xhtml
http://localhost:8080/myproject/folder_a I get a content from WebContent/folder_a/index.xhtml
http://localhost:8080/myproject/folder_b I get a content from WebContent/folder_b/index.html
Does the .xhtml file contain JSF content? is it parsed? I always
thought defining a jsf/facelets file as a welcome file did not work
and you needed http redirects via 'meta-inf'
.jsf' is that an extension I am using in myweb.xml` file:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Please read answers for the below question to learn what it is:
JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
What is the difference between creating JSF pages with .jsp or .xhtml or .jsf extension
JSF 2.0 does not have support for extensionless URL by default. This is a long waited feature for the community, but finally we got this with JSF 2.3 (released early 2017). If you care able to update your application to JSF 2.3, or maybe want some more information, please check it out here.
A brief example of how you can make the default JSF approach for extensionless URLs:
In the web.xml file, include each desired mapping using a tag inside the tag:
<url-pattern>/page1</url-pattern>
<url-pattern>/page2</url-pattern>
<url-pattern>/path/page1</url-pattern>
These patterns will redirect the user to the following paths respectively:
www.domain.com/page1 -> www.domain.com/page1.xhtml
www.domain.com/page2 -> www.domain.com/page2.xhtml
www.domain.com/path/page1 -> www.domain.com/path/page1.xhtml
Note that the above examples are not providing a way to redirect to the index.xhtml page, they are just a example of how the new JSF 2.3 mapping work.
However, if you can't update your project right now, I suggest you to follow #Kukeltje advice and take a look on the PrettyFaces library.
PrettyFaces is focused on provide a simple way to create URL mappings for older JSF versions. Heres a example of how it works:
In the pretty-config.xml file, include your desired mappings using a tag:
<url-mapping id="view-page">
<pattern value="/page" />
<view-id value="/page/index.xhtml" />
</url-mapping>
<url-mapping id="view-page-edit">
<pattern value="/page/#{id}" />
<view-id value="/page/edit.xhtml" />
</url-mapping>
These patterns would work like the following examples:
www.domain.com/page -> www.domain.com/page/index.xhtml
www.domain.com/page/2 -> www.domain.com/page/edit.xhtml?id=2
Both are good alternatives, PrettyFaces looks more powerful right now, since they are support this kind of solution for more time, but the JSF 2.3 should also do the trick.
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.
Is there any way to reuse jsp -custom tags inside a html file?
My custom tag is already defined in a tld file and I am using that custom tag in a jsp file.
I want to reuse that custom tag in a html file.
How do I do this?
Below is the sample example of using my custom tag(btc:content) in a jsp file.
<div class="sfl-section-body">
<btc:content name="HOL-CF-307" />
I want to use (my custom tag) in an html file.
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.