从 JSF 页面中删除附加标头

发布于 2024-12-24 02:22:05 字数 800 浏览 5 评论 0原文

我使用以下代码编写了一个 .xhtml 页面:

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

我正在新窗口中使用 JavaScript 打开此页面。

不幸的是,它显示为

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

“这当然是无效的 HTML”。如何删除那些附加的标签?首先为什么要创建它们?

我正在使用 JSF 1.2、Facelets、Portlet API 2.0 和 JBoss PortletBridge。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゃ人海孤独症 2024-12-31 02:22:05

尝试使用 jsf head 和 body 组件:

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

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>
随梦而飞# 2024-12-31 02:22:05

您应该使用带有组件的模板,然后在您的页面中使用

例子
模板

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

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

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>
仅此而已 2024-12-31 02:22:05

我现在已经编写了一个 HttpServlet 的弹出窗口可以规避这个问题。由于转发到的文件以 *.jsp 结尾,因此它不受 FacesServlet 并且没有奇怪的标头被附加。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文