1

I've written an .xhtml page with the following code:

<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        <p>P</p>
    </body>
</html>

I'm opening this page with JavaScript in a new window.

Unfortunately it's displayed as

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    </head>
    <div id="">
        <html>
            <head>
                <title>Test</title>
            </head>
            <body>
                <p>P</p>
            </body>
        </html>
    </div>
</html>

This of course is invalid HTML. How can I remove those appended tags? And why are they created in the first place?

I'm using JSF 1.2, Facelets, the Portlet API 2.0 and JBoss PortletBridge.

  • You should use a template with components and then in your page – roel Jan 02 '12 at 12:57
  • Sounds much like as if the request URL fired by JS did not match `FacesServlet` URL pattern as specified in `web.xml`. Please verify this. I'm not sure what the role/influence of a portlet API is as I've never used it, so I am not posting this directly as an answer. – BalusC Jan 02 '12 at 13:50
  • The pattern is `*.xhtml` and the URL ends with `.xhtml`. –  Jan 02 '12 at 14:23
  • Oh? Does that work for normal pages which you don't open by JS? – BalusC Jan 02 '12 at 15:15

3 Answers3

0

Try using the jsf head and body components:

<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core">
    <f:view>
        <h:head>
            <title>Test</title>
        </h:head>
        <h:body>
            <p>P</p>
        </h:body>
    </f:view>
    </html>
Efthymis
  • 1,326
  • 11
  • 13
0

You should use a template with components and then in your page

example template

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:head>
<title><ui:insert name="title">Default title</ui:insert></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body dir="ltr">
<ui:insert name="content" />
</h:body>
</html>

and the a .xhtml page

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
>
<html>
    <head></head>
    <body>
<ui:composition template="${empty param.sl ? '/includes/template.xhtml' : '/includes/templatepopup.xhtml'}">
    <ui:define name="title">${msg.removeapplicant_title}</ui:define>
<ui:define name="content">
        <f:view>


put your htlml here

</f:view>
    </ui:define>
</ui:composition>
</body></html>
</f:view>
roel
  • 2,005
  • 3
  • 26
  • 41
  • Actually I've use a template and got the described problem. I've omitted it in the question just for simplicity. –  Jan 02 '12 at 13:25
  • You are implying that using template client is required in order to retrieve a proper HTML result. This is untrue. – BalusC Jan 02 '12 at 13:52
0

I've now written a HttpServlet for the pop-up to circumvent this problem. Since the file to which it's forwarding is ending with *.jsp, it's not affected by the FacesServlet and no strange header gets appended.