简体   繁体   English

从JSF页面中删除附加的标题

[英]Remove appended header from JSF page

I've written an .xhtml page with the following code: 我用以下代码编写了一个.xhtml页面:

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

I'm opening this page with JavaScript in a new window. 我要在新窗口中使用JavaScript打开此页面。

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. 这当然是无效的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. 我正在使用JSF 1.2,Facelets,Portlet API 2.0和JBoss PortletBridge。

Try using the jsf head and body components: 尝试使用jsf头部和身体组件:

<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>

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 和一个.xhtml页面

!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>

I've now written a HttpServlet for the pop-up to circumvent this problem. 我现在为弹出式窗口编写了HttpServlet来解决此问题。 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. 由于转发到的文件以*.jsp结尾,因此不受FacesServlet的影响,并且不会附加任何奇怪的标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM