使用映射的URL和操作的PrettyFaces,我失去了所有样式 [英] PrettyFaces using mapped urls and actions, i lose all my stylings

查看:78
本文介绍了使用映射的URL和操作的PrettyFaces,我失去了所有样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开始使用映射的URL功能(第3.6节)之前,我一直在为URL使用漂亮的面孔. http://ocpsoft.org/docs/prettyfaces/3.3.3/zh-CN/html/Configuration.html#config.actions

I have been using pretty faces for urls without issue until i started using mapped URLs feature (Section 3.6). http://ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/Configuration.html#config.actions

我得到的输出和我想发生的动作都很好.问题是我无法进入资产文件夹下的任何资产.我得到的是404.奇怪的是,对于其他所有配置,都没有问题.当我一起运行它们时,这不是问题.该应用程序使用的是模板,因此指向CSS,JS等的链接完全相同.当我转到普通的ol'(例如/home)映射时,它们可以正常工作,请转到另一页并执行相应操作,否则它们将无法正常工作.模板渲染确实可以.实际上,参数注入和操作也可以.

I'm getting the output and the actions i want to happen working fine. The problem though is i can't get to to any of my assets under assets folder. i'm getting a 404. The weird thing is that for every other config there hasn't been a problem. And isn't a problem when I run them together. The app is using a template so the links to css's, js's, etc.. are exactly the same. When I go to a plain ol' (e.g. /home) mapping they work fine, go to the other page with the action, they don't work. The template rendering does though. In fact the parameter injection and the action work as well.

PRETTY CONFIG:

PRETTY CONFIG:

<url-mapping id="home"> <!-- assets work -->
    <pattern value="/home" />
    <view-id value="/home.jsf" />
</url-mapping>
<url-mapping id="validate-token"> <!-- assets don't work -->
  <pattern value="/validate-token/type/#{id:validateByTokenController.tokenType}/token/#{validateByTokenController.token}" />
  <view-id value="/validate-token.jsf" />
  <action>#{validateByTokenController.init}</action>
</url-mapping>

豆豆:

@RequestScoped
@Named
public class ValidateByTokenController {

private String tokenType;

private String token;

public void init() {
    token = "J" + token;
    tokenType = "J" + tokenType;
}

XHTML样本CSS链接:("home"配置的链接相同,但"validate-token"的链接相同)

XHTML SAMPLE CSS LINKS: (same links for "home" config, but not for "validate-token")

<link rel="stylesheet"
    href="assets/plugins/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="assets/css/style.css" />

谢谢.

推荐答案

问题是您正在为CSS文件使用相对URL.

The problem is that you are using relative URLs for your CSS files.

使用类似/validate-token/type/foo/token/bar的URL,浏览器认为/validate-token/type/foo/token/是当前目录.因此,他尝试从/validate-token/type/foo/token/assets/css/style.css加载CSS文件.

With an URL like /validate-token/type/foo/token/bar the browser thinks that /validate-token/type/foo/token/ is the current directory. So he tries to load the CSS file from /validate-token/type/foo/token/assets/css/style.css.

尝试为CSS使用绝对URL:

Try using absolute URLs for your CSS instead:

<link rel="stylesheet" href="#{request.contextPath}/assets/css/style.css" />

这篇关于使用映射的URL和操作的PrettyFaces,我失去了所有样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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