PrimeFaces CSS皮肤未显示在登录页面中,也出现JavaScript未定义错误 [英] PrimeFaces CSS skin not showing in login page, also JavaScript undefined errors

查看:101
本文介绍了PrimeFaces CSS皮肤未显示在登录页面中,也出现JavaScript未定义错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Web应用程序中使用PrimeFaces 3.4,对于特定页面,控件不显示为具有普通PrimeFaces皮肤:

I am using PrimeFaces 3.4 in my web app and for a particular page the controls are not displayed with the normal PrimeFaces skin:

<!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"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>VMS login</title>
</h:head> 
<h:body> 
  <h:form id="loginForm">
    <p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />  
    <p:panel header="#{msgs['login.title']}">
      <p:panelGrid id="loginPanel" columns="2">
        <h:outputText value="#{msgs['login.username']}" />
        <p:inputText id="j_username" value="#{loginFormBean.userName}" required="true"></p:inputText>
        <p:message for="j_username" ></p:message>
        <h:outputText value="#{msgs['login.password']}" />
        <p:password id="j_password" value="#{loginFormBean.password}" required="true" feedback="false"></p:password>
        <p:message for="j_password"></p:message>
        <p:commandButton action="#{loginController.loginUsingSpringAuthenticationManager}" value="#{msgs['login.button']}" update="loginForm" ajax="true"></p:commandButton>
      </p:panelGrid>
    </p:panel>
  </h:form>
</h:body>
</html>

这输出到:

面板上应有标题等.

有趣的是,在另一个我使用<p:layout>且在布局中具有不同面板的页面中,它们具有正常的PrimeFaces外观很好地显示.

The interesting thing is that in another page where I am using a <p:layout> with different panels in the layouts they display fine with their normal PrimeFaces look-and-feel.

我做错了什么?谢谢

推荐答案

鉴于它仅出现在登录页面上,这可能在身份验证机制还启动对CSS/JS/图像文件等JSF资源的请求并进行重定向时发生他们也进入登录页面.然后,网络浏览器将检索登录页面的HTML表示形式,而不是具体资源.如果您已经研究了Web浏览器开发人员工具集中的HTTP流量,那么您也应该注意到这一点.

Given that it only occurs on the login page, that can happen when the authentication mechanism also kicks on requests to JSF resources like CSS/JS/image files and redirects them to the login page as well. The webbrowser would then retrieve the HTML representation of the login page instead of the concrete resources. If you have investigated the HTTP traffic in the webbrowser's developer toolset, then you should have noticed that as well.

如果您将本地认证与servlet过滤器一起使用,则需要告诉过滤器不要将其重定向到登录页面,而只是继续进行.这些是/javax.faces.resource/* URL(您可以通过 ResourceHandler#RESOURCE_IDENTIFIER ).

If you're using homegrown authentication with a servlet filter, then you need to tell the filter to not redirect them to the login page, but just continue them. It are those /javax.faces.resource/* URLs (you can get that URL path as constant by ResourceHandler#RESOURCE_IDENTIFIER).

if (request.getRequestURI().startsWith(request.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) {
    chain.doFilter(request, response);
    return;
}

// ...

或者,如果您使用的是容器管理的身份验证,则应在允许的网址中添加/javax.faces.resource/*,该网址应从登录检查中跳过:

Or if you're using container managed authentication, then you should add /javax.faces.resource/* to allowed URLs which should be skipped from login checks:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Allowed resources</web-resource-name>
        <url-pattern>/javax.faces.resource/*</url-pattern>
    </web-resource-collection>
    <!-- No Auth Contraint! -->
</security-constraint>

另请参见排除css和web.xml安全约束中的图片资源.

或者当您使用诸如Spring Security之类的第三方身份验证框架时,则需要通过以下方式(假设使用3.1.0或更高版本)来告诉它

Or when you're using 3rd party authentication framework like Spring Security, then you need to tell it the following way (assuming 3.1.0 or newer)

<http security="none" pattern="/javax.faces.resource/**" />

另请参见 Spring Security 3.0.5 .

或者在使用PicketLink时,请参见

Or when you're using PicketLink, see PrimeFaces based application with PicketLink does not show style in login page.

这篇关于PrimeFaces CSS皮肤未显示在登录页面中,也出现JavaScript未定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆