Forums de discussion

Double doctype, head and body tag

Fredrik Jensen, modifié il y a 7 années.

Double doctype, head and body tag

New Member Publications: 4 Date d'inscription: 15/03/16 Publications récentes
Hi,
We have discovered that some of our pages have duplicate tags and scripts. Some of our portlet, create their own doctype, <head> and <body>.

Suspect it has to do with the PrimeFaces / PrimeFaces Mobile. Has anyone had similar problems?

<!DOCTYPE html>

<head>
some data
</head>
<body>
//Portlet
<!DOCTYPE html>
<head>
some data
</head>
<body>
</body>
//End of portlet
</body>

Versions
Liferay 6.2 ce Ga6 (bundled with tomcat 7.0.62),
Liferay Faces 4.2.5-ga6
PrimeFaces 5.3
JSF 2.2
in Faces-config.xml (<default-render-kit-id>PRIMEFACES_MOBILE</default-render-kit-id>)

Liferay runs on windows 2012 server with Java 1.8.0_60
thumbnail
Kyle Joseph Stiemann, modifié il y a 7 années.

RE: Double doctype, head and body tag

Liferay Master Publications: 760 Date d'inscription: 14/01/13 Publications récentes
Hi Fredrik,
Primefaces Mobile does not work with Liferay Faces GA6 because it uses a different RenderKit Id than HTML_BASIC. We've already created FACES-2910 to track a similar issue (with our new modular jars), and I'm currently working on it now. I will let you know when a SNAPSHOT with that fix has been released so you can try it.

- Kyle
thumbnail
Kyle Joseph Stiemann, modifié il y a 7 années.

RE: Double doctype, head and body tag

Liferay Master Publications: 760 Date d'inscription: 14/01/13 Publications récentes
Fredrik Jensen, modifié il y a 7 années.

RE: Double doctype, head and body tag

New Member Publications: 4 Date d'inscription: 15/03/16 Publications récentes
Hi Kyle.
We have tested the new versions according liferayfaces.org for Liferay 6.2, JSF 2.2 and primefaces plus your new snapshot (4.0.1-SNAPSHOT).

It looks much better with memory and some html tags but our problem with multiple doctypes remains.
------------------------------------------------------
<! DOCTYPE html>
<Html class = "AUI ltr" dir = "ltr" lang = "EN-GB">
<Head>
---
</ Head>
<Body class = "yui3-skin-sam controls visible-site guest-signed-in private-page site">
<! DOCTYPE html>
<Div id = "_ Ansokan_WAR_Ansokan_" class = "Liferay-faces-bridge-body" id = "_ Ansokan_WAR_Ansokan_" class = "Liferay-faces-bridge-body"> <div id = "_ Ansokan_WAR_Ansokan_: j_idt8" class = "ui-messages ui widget TRM-error "aria-live =" polite "> </ div>
------------------------------------------------------

We are now checking our JSF 2.2 implementation with JSF templates, <ui:composition , ui:include, ui:fragment and composite components
Micael Ericsson, modifié il y a 7 années.

RE: Double doctype, head and body tag

Regular Member Publications: 169 Date d'inscription: 11/12/12 Publications récentes
Hi

Discussing this matter with Fredrik and continued on my Demo flow portlet (another thread with Neil) I was able to reproduce this problem.

1) Running my demo flow and checking page source on first flow page (demoflow.xhtml) - only one doctype.
2) Creating a template with header, footer and content sections. Creating footer and header xhtml. Using this template from my flow pages.
3) Running and checking page source again. This time the page source has two doctypes.
(Syntax for template is based upon sample from https://www.mkyong.com/jsf2/jsf-2-templating-with-facelets-example/)

Apparently the combination of Liferay, JSF 2.2, portlet, and ui:composition generates double doctypes.

I provided the demo project with this post. Please check it our to see if I am missing something.

Regards,
Micael
thumbnail
Vernon Singleton, modifié il y a 7 années.

RE: Double doctype, head and body tag

Expert Publications: 315 Date d'inscription: 14/01/13 Publications récentes
Hi Micael and Fredrik,
Micael Ericsson:
Apparently the combination of Liferay, JSF 2.2, portlet, and ui:composition generates double doctypes.

I provided the demo project with this post. Please check it our to see if I am missing something.

After taking a look at your demo portlet, there are several things you will need to address.

1) You must be seeing errors like this in your server log files:
21:25:19,370 INFO  [ContainerBackgroundProcessor[StandardEngine[Catalina]]][PortletHotDeployListener:344] Registering portlets for DemoFlow
21:25:19,378 ERROR [ContainerBackgroundProcessor[StandardEngine[Catalina]]][PortletLocalServiceImpl:834] com.liferay.portal.kernel.xml.DocumentException: Error on line 13 of document  : The content of element type "portlet" must match "(portlet-name,icon?,virtual-path?,struts-path?,parent-struts-path?,configuration-path?,configuration-action-class?...

So you will need to make sure that the friendly-url-mapper-* elements are declared before the instanceable element, and get rid of any such issues with the order that elements are declared in your liferay-portlet.xml file.

2) and errors like this:
Caused by: org.dom4j.DocumentException: Error on line 9 of document  : Attribute "name" is required and must be specified for element type "ignored-parameter". Nested exception: Attribute "name" is required and must be specified for element type "ignored-parameter".
	at org.dom4j.io.SAXReader.read(SAXReader.java:482)

So you will need to make sure that your ignored-parameter element has a name attribute. You will also want to place the ignored-parameter element above the implicit-parameter, since the ordering for the friendly-url-routes xml files requires this. Also your ignored-parameter should not need the (_DemoFlow_WAR_DemoFlow10SNAPSHOT_) portlet namespace in it, just the name of the parameter.

3) the reason you are probably seeing the "double doctypes" as you call them is that you are including the DOCTYPE in your xhtml files:
$ grep DOC src/main/webapp/demoflow/*.xhtml
src/main/webapp/demoflow/flowFooter.xhtml:
<br>It looks like you folks are keen to having your application run as both a plain web application and run as a portlet. Since that is the case, I suggest you take a careful look at our showcase demo, which is exactly that. Start by looking here at <a href="http://www.liferayfaces.org/web/guest/jsf-showcase/-/jsf-tag/h/body/general">the h:body tag example</a> in our jsf-showcase-portlet.<br><br>Notice that the DOCTYPE is not needed in the portlet environment, so it is not included in the portletBody.xhtml. Next, look here at <a href="https://github.com/liferay/liferay-faces-showcase/blob/master/jsf-showcase-webapp/src/main/webapp/views/home.xhtml#L4">our jsf-showcase-webapp home.xhtml</a> file.<br><br>The ui:composition tag declares a template which chooses the webapp xhtml or the portlet xhtml on the fly. This is the way we recommend that you allow your application to work as both a plain webapp and a portlet. Also, this prevents the DOCTYPE from being used in the portlet.<br><br>This brings us to another issue:<br>4) You have plain "body" tags in your xhtml files, for example, src/main/webapp/demoflow/flowHeader.xhtml. Those body tags do not belong in a portlet. Consider using f:view instead of the "html" tag in a portlet. Again, if you follow our showcase webapp and showcase portlet examples, you will see that plain body tags are never used or needed.<br><br>As you stated, "the page source has two doctypes", but if you correct all of the issues listed above, you will see that the second DOCTYPE that you put in the xhtml files will not show up in your page source, you will see fewer errors in your logs, and if you carefully follow the examples in our showcase, you will be able to create an application that runs as both a webapp and a portlet.<br><br>Hope that helps,<br>Vernon
Micael Ericsson, modifié il y a 7 années.

RE: Double doctype, head and body tag

Regular Member Publications: 169 Date d'inscription: 11/12/12 Publications récentes
Hi Vernon

Thanks for taking time to look at our problem.

You are correct that we are mixing web app and portlet and our demo project. This is a sample, in our real project our aim is portlets only.
The Doctype in template/header/footer was from sample which is intended for webapp. Great that doctype is not needed for portlets. Removing all doctypes and replacing body with h:body resolved our problem with double doctypes, both in the sample demo and in our production portlets. Big thanks!

Regarding errors in log and friendly url mapping I havn't been equally succesful. I have none of those errors you describe. Perhaps this is good and there is a environmental difference, I don't know. Regarding friendly url I am not sure if I understood your suggestion:
So you will need to make sure that the friendly-url-mapper-* elements are declared before the instanceable element, and get rid of any such issues with the order that elements are declared in your liferay-portlet.xml file.

What I thought and did was, in liferay-portlet.xml, moving all firendly-url mapping to top of "portlet" section. I also moved "ignore" mapping first of mappings. This didn't help firendly url presentation. Still long not friendly urls:
https://xxx:8443/test/-/df/demoFlowIntro?p_auth=XDouWBQA&_DemoFlow_WAR_DemoFlow10SNAPSHOT_javax.faces.ClientWindow=A0D56F87DE00872F8B0C4C4AF485FC78%3A_DemoFlow_WAR_DemoFlow10SNAPSHOT_%3A0

I tried different name settings on "xxxClientWindow" but none helped. Any suggestions on how to get friedly urls correct?
thumbnail
Vernon Singleton, modifié il y a 7 années.

RE: Double doctype, head and body tag

Expert Publications: 315 Date d'inscription: 14/01/13 Publications récentes
Hi Micael and Fredrik,

Micael Ericsson:
Big thanks!

Glad to hear that you no longer have two DOCTYPEs in your pages.

Micael Ericsson:
... Still long not friendly urls:
https://xxx:8443/test/-/df/demoFlowIntro?p_auth=XDouWBQA&_DemoFlow_WAR_DemoFlow10SNAPSHOT_javax.faces.ClientWindow=A0D56F87DE00872F8B0C4C4AF485FC78%3A_DemoFlow_WAR_DemoFlow10SNAPSHOT_%3A0

I tried different name settings on "xxxClientWindow" but none helped. Any suggestions on how to get friedly urls correct?

Maybe you missed my suggestion to adjust the ignored-parameter element in your friendly-url-routes.xml. Below is a route that I have adjusted for you a little bit. This route may not be what you want because I am not sure what you require of your urls, but it definitely addresses your "still long not friendly urls" issue.
   <route>
      <pattern>/demoFlowIntro</pattern>
      <ignored-parameter name="javax.faces.ClientWindow"></ignored-parameter>
      <implicit-parameter name="_facesViewIdRender">/views/demoFlowIntro.xhtml</implicit-parameter>
      <implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
   </route>

Unlike the ignored-parameter elements in the routes you attached, the ignored-parameter element here:
  • is listed after the <pattern> element, but before the <implicit-parameter> elements.
  • has a "name" attribute .
  • does not contain the portlet namespace. The name only contains the parameter name "javax.faces.ClientWindow".
The order that these elements need to appear in the xml document are governed by the xml dtd and schema. Anyway, when I visit the demoFlowIntro page with the route above, I get a url that looks like this:
http://localhost:8080/web/guest/flow/-/df/demoFlowIntro?p_auth=nxYfTxiG

If you need further help regarding friendly urls, you should post your questions in the normal Development forum.

Hope that helps,
Vernon
Micael Ericsson, modifié il y a 7 années.

RE: Double doctype, head and body tag

Regular Member Publications: 169 Date d'inscription: 11/12/12 Publications récentes
Hi Vernon

Thanks for your input. I have missed the name tag for ignored-parameter. Now everything is working as is should.

Regards,
Micael
thumbnail
Vernon Singleton, modifié il y a 7 années.

RE: Double doctype, head and body tag

Expert Publications: 315 Date d'inscription: 14/01/13 Publications récentes
Micael Ericsson:
Now everything is working as is should.

Glad to hear that things are working for you.

Enjoy using Liferay.

- Vernon