JSF Create embedded browser nested [duplicate] - jsf

This question already has an answer here:
JSF Facelets how to include external html?
(1 answer)
Closed 6 years ago.
I need to create a web site and open a another web html inside(nested), the html must to be inside a composite. Any idea?
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="./welcomePrimefaces.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<ui:define name="contenido">
external web site?????
</ui:define>
</ui:composition>

<ui:composition>
allows you to include JSF templates which have code snippets. These templates must be avialble within the same classloader.
If you want to embed an external page into your page, you need to use iframe.
For example:
<iframe src="http://www.primefaces.org/showcase/ui/home.jsf"/>
You can place this on the page and point it to the external website.

Related

How to use JSF templates stored in a shared jar?

I am trying to store a set of JSF templates and other resources in a .jar file, which several webapps will draw from. I found this SO answer, which seems to provide instructions for the very thing I'm trying to do. However, while I can load images from the shared jar, I cannot get JSF templates to work. I get a file not found error.
I'm using Open Liberty 18.0.0.4, and the jar is stored in the ${server.config.dir}/lib/global directory, which I understand makes the contents available to all webapps.
Here is the output of jar tf of the shared jar.
META-INF/MANIFEST.MF
META-INF/resources/common/images/ufo.png
META-INF/resources/common/jsf/template.xhtml
This is the template.xhtml from the shared jar.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Title from template</title>
</h:head>
<h:body>
This is content from the template<br/>
</h:body>
</html>
Turning to my webapp, here is the directory layout.
/WEB-INF
/WEB-INF/classes
/WEB-INF/web.xml
/META-INF
/imageTest.xhtml
/localTemplate.xhtml
/localJSFTest.xhtml
/sharedJarJSFTest.xhtml
The imageTest.xhtml simply displays the ufo.png from the shared jar, and this facelet works without a problem.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Test Image</title>
</h:head>
<h:body>
I can see this image.<br/>
<h:graphicImage library="common" name="images/ufo.png" alt="ufo"/>
</h:body>
</html>
The localJSFTest.xhtml uses the localTemplate.xhtml, which is part of the webapp. This also works.
localJSFText.html
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:body>
<ui:composition template="localTemplate.xhtml" />
</h:body>
</html>
localTemplate.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Title from local template</title>
</h:head>
<h:body>
This is content from the LOCAL template<br/>
</h:body>
</html>
The problem comes when sharedJarJSFText.xhtml tries to use template.xhtml (posted above) from the shared jar.
sharedJarJSFText.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:body>
<ui:composition template="/common/jsf/template.xhtml" />
</h:body>
</html>
I get the following error when I try to access sharedJarJSFText.xhtml in the browser.
/common/jsf/template.xhtml Not Found in ExternalContext as a Resource
viewId=/sharedJarJSFTest.xhtml
location=/home/jmac/Programming/NetBeansProjects/TestJSFWebApp/src/main/webapp/sharedJarJSFTest.xhtml
phaseId=RENDER_RESPONSE(6)
Caused by:
java.io.FileNotFoundException - /common/jsf/template.xhtml Not Found in ExternalContext as a Resource
at org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:300)
I think I'm following the instructions in the above linked SO answer, so I'm not sure why this isn't working.
In another SO answer, user BalusC explains that since the Servlet 3.0 spec writing a custom ResourceResolver is unnecessary. This version of Open Liberty uses the Servlet 4.0 spec.
If helpful, here is the feature list from the server.xml for this Open Liberty server.
<featureManager>
<feature>jsp-2.3</feature>
<feature>jsf-2.3</feature>
</featureManager>
Thanks in advance for any suggestions.

ui:include includes wrong file in JSF 2.2

Accorrding to the documentation of ui:include tag
Use this tag—which is very similar to JSP's jsp:include—to encapsulate
and reuse content among multiple XHTML pages. There are three things
this tag can include: plain XHTML, and XHTML pages that have either a
composition tag or a component tag.
You supply a filename, through ui:include's src attribute for JSF to
include. That filename is relative to the XHTML file that was rendered
as a result of the last request. So, for example, if JSF loaded the
view login.xhtml, and that file included pageDecorations/header.xhtml,
and pageDecorations/header.xhtml included companyLogo.xhtml, then
companyLogo.xhtml will not be found if it's in the pageDecorations
directory, because companyLogo.xhtml has to be in the same directory
as login.xhtml.
I created a simple test:
webapp/login.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:body>
<ui:include src="pageDecorations/header.xhtml" />
</h:body>
</html>
webapp/pageDecorations/header.xhtml
<ui:include
src="logo.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
/>
webapp/pageDecorations/logo.xhtml
<h:outputText
value="Logo in /pageDecorations"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
/>
webapp/logo.xhtml
<h:outputText value="Logo in /"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
/>
When I ran this test (loaded login.xhtml page) using JSF 2.2 on WildFly 10.1 , I got Logo in /pageDecorations, while according to the documentation it should be: Logo in /
What is wrong ? Is there a bug in the documentation or Mojarra implementation ? Or my understanding is wrong ?
First, you are inside webapp/ and executing webapp/login.xhtml
inside that you get src="pageDecorations/header.xhtml" and for exectuing that you are in pageDecorations and from header.xhtml you are tring to find src="logo.xhtml" which will you get in the same directory (pageDecorations) so it will print
"Logo in /pageDecorations" .
Document looks wrong in this case.

JSF Input Text Placeholder

I am using JSF 2.2 and I am trying to put a placeholder on some input text.
<h:inputText value="#{loginBean.studentId}" id="username" a:placeHolder="Username"/>
I have placed the following in the head of my xhtml document and added the
pass through name space:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"htth://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
However, I receive the following warning and the placeholder does not render on my page:
Can't find facelet tag library for uri http://xmlns.jcp.org/jsf/passthrough
Thanks for any help and advise.

JSF Facelets how to include external html?

I have an app that i'm developing and my company has a header banner that is required to be on all pages. We have about 6 different versions floating around my team of that header banner and I now want to make it so that I just include the banner from the source into my app so that if they update the source of the banner, my app's version of the banner is automatically updated as well.
using <ui:include src="http://mycompany.com/banner.html" /> causes the error The markup in the document following the root element must be well-formed..
How can i include this banner even if it's not well formed xml?
My current template:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition>
<h:body>
<div>
<ui:include src="http://mycompany.com/banner.html" />
</div>
<ui:insert name="content" />
</h:body>
</ui:composition>
</html>
The Facelets <ui:include> tag is the wrong tool for the purpose of embedding external resources in a HTML document.
Use the HTML <iframe> element instead.
<iframe src="http://mycompany.com/banner.html"></iframe>

How to make facelets conform to XHTML 1.0 Transitional?

Why can't facelets XHTML files be valid XHTML 1.0 Transitional files?
If I submit a facelet file in an xml validator (e.g. w3c validator) it shows an error on the first tag defined in one of the taglibs.
Example 1:
If I submit the following file to the validator, it shows no error, validation goes fine because no taglib tags appear in the document (one jsf taglib is defined though).
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
<head>
<title></title>
</head>
<body>
</body>
</html>
Example 2:
Now I just inserted the h:head and h:body tags from the xmlns:h namespace but this causes errors in the validation.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title></title>
</h:head>
<h:body>
</h:body>
</html>
Certainly I'm missing something fundamental here, but I still can't figure out what.
This is my first question here at S.O. so please point out any errors, thank you!
If you check the Lifecycle of a Facelets Application you can see that your view is rendered to the client. This will transform tags like <h:head> replacing them with their xhtml equivalent e.g. <head>. If you want templates that are XHTML valid you may want to try with the jsfc attribute but it has its drawbacks.

Resources