如何从Java Faces应用程序中删除默认主题?

时间:2023-01-21 19:20:15

I've never used Java before (C# is my domain), but now I have a task that I must apply a specific style to for a tiny Java webpage. The style is from another ASP.NET application that we're rolling out and that I've helped to develop. Seems that this style is on the way to become our new company web-style. :P

我以前从未使用过Java(C#是我的域名),但现在我有一个任务,我必须为一个小的Java网页应用特定的样式。这个样式来自我们正在推出的另一个ASP.NET应用程序,并且我帮助开发了它。似乎这种风格正在成为我们新的公司网络风格。 :P

The webpage is really tiny - it has only a login form and an action form with a dozen textboxes and a button. When you click the button, a file is generated and available for download.

网页非常小 - 它只有一个登录表单和一个带有十几个文本框和一个按钮的动作表单。单击该按钮时,将生成一个文件并可供下载。

This application has already been made by a colleague of mine, who has good experience with Java, but nearly no experience with the web. So he's no help anymore. For now the application has NO style at all. Just a bunch of textboxes.

这个应用程序已经由我的同事制作,他有很好的Java经验,但几乎没有网络经验。所以他再也没有帮助了。目前,应用程序根本没有风格。只是一堆文本框。

The application is made in NetBeans and Java Faces - as far as I understand. Or maybe it's "Visual Faces". Not sure - can't make heads or tails with all these names from the Java world. Anyway, it's this ASP.NET look-alike where you have an XML page with tags like <ui:textField> and <ui:passwordField>, and then a code-behind file with all your Java code. (Actually I suspect that ASP.NET was created after this, but that's besides the point)

应用程序是在NetBeans和Java Faces中完成的 - 据我所知。或者也许它是“视觉面孔”。不确定 - 不能用Java世界中的所有这些名称做出正面或反面。无论如何,这个ASP.NET看起来很相似,你有一个带有 标签的XML页面,然后是一个包含所有Java代码的代码隐藏文件。 (实际上我怀疑ASP.NET是在此之后创建的,但除了这一点之外)

I've successfully converted the HTML layout to the one I need and set my own CSS/JavaScript files in the header. There's just one problem - the Faces thing is hell-bent on including its own CSS stylesheets as well. Sounds reasonable of course, but for some mind-boggling reason these stylesheets also deem it necessary to override styles on all the common tags - <body>, <div>, <span>, etc. Which is annoying, because that breaks my design. Now, I could change my own stylesheets to over-override these default Faces stylesheets, but that seems... well, not the right solution. It's like a workaround, not a "correct" solution. Why should I redefine font attributes for every tag, when it should easily cascade down from the "body" tag?

我已成功将HTML布局转换为我需要的布局,并在标题中设置我自己的CSS / JavaScript文件。只有一个问题 - Faces事情本身就是包含自己的CSS样式表。当然听起来很合理,但是出于某些令人难以置信的原因,这些样式表还认为有必要覆盖所有常见标签上的样式 - ,

, 等。这很烦人,因为这会破坏我的设计。现在,我可以更改自己的样式表来覆盖这些默认的Faces样式表,但这似乎......好吧,不是正确的解决方案。这就像是一种解决方法,而不是“正确”的解决方案。为什么我应该重新定义每个标签的字体属性,何时它应该很容易从“body”标签向下级联?

Is there any way how I can tell Faces not to include its own stylesheets? I won't be using any of their controls anyway - just textboxes and buttons. And labels, when I find them. :P

有什么方法可以告诉Faces不要包含自己的样式表吗?我不会使用他们的任何控件 - 只是文本框和按钮。和标签,当我找到它们。 :P

Oh, yes, and I tried to re-create it all in simple JSP (no Faces), but that failed, because the code-behind (there's some big library there) is dependent on it... This is also the reason why I can't move it to the ASP.NET I'm so familiar with.

哦,是的,我试图在简单的JSP(没有Faces)中重新创建它,但是失败了,因为代码隐藏(那里有一些大型库)依赖于它......这也是为什么我无法将它移动到我熟悉的ASP.NET。


Added: Since it seems there are many Java Faces frameworks out there, here's a snippet of code that might help:

<jsp:root version="1.2" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:ui="http://www.sun.com/web/ui">
    <jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
        <f:view>
            <ui:page id="page1">
                <ui:html id="html1">
                    <ui:head id="head1">

Also I forgot to mention that there is a folder in NetBeans called "Sun Web UI Components Themes" which has three items under it - "Gray Theme", "Green Theme" and "Default Theme". I can choose one of them as the active one, and that also changes the CSS which is included by default. Unfortunately I cannot choose none.

另外我忘了提到NetBeans中有一个名为“Sun Web UI组件主题”的文件夹,其中有三个项目 - “灰色主题”,“绿色主题”和“默认主题”。我可以选择其中一个作为活动的,这也改变了默认包含的CSS。不幸的是我不能选择任何一个。

OK, I already changed my style to override these stylesheets. Still it would be nice to hear more about what I'm dealing here with. I don't even know where I should look for documentation...

好的,我已经改变了我的风格来覆盖这些样式表。听到更多关于我在这里处理的事情,仍然会很高兴。我甚至不知道应该在哪里找文件......

Added 2: Also, the namespace for say, TextField, is com.sun.rave.web.ui.component.

添加2:此外,TextField的命名空间是com.sun.rave.web.ui.component。

1 个解决方案

#1


Which JSF (JavaServer Faces) library is this using? MyFaces? RichFaces? Something different?
I don't know if you've found this resource yet: JSF Tag lib. If it's using <ui: type tags, then it's also using Facelets which is a templating system for JSF. However the tag parameter you are probably looking for is styleClass and Style.

这个使用哪个JSF(JavaServer Faces)库? MyFaces的? RichFaces的?有些不同?我不知道你是否找到了这个资源:JSF Tag lib。如果它使用 标签,那么它也使用facelets,它是jsf的模板系统。但是,您可能正在寻找的tag参数是styleclass和style。

There really isn't a default styling for standard JSF, and I think there's probably another JSF library that's being used. Under the WEB-INF directory is probably a directory called lib where the jar files are. Those should give you a clue as to what library's are being used.

确实没有标准JSF的默认样式,我认为可能还有另一个正在使用的JSF库。在WEB-INF目录下可能是一个名为lib的目录,其中包含jar文件。那些应该给你一个关于什么库使用的线索。

RichFaces comes with its own styling, and is completely themeable. In your particular case, it's going to be more of a pain than it's worth for your situation. Other JSF library's may do the same.

RichFaces拥有自己的造型,完全可以打造主题。在你的特殊情况下,它会比你的情况更值得痛苦。其他JSF库也可以这样做。

Unfortunately I can only point you at places and ideas of where the problem might be. Given the vast number of choices when it comes to JSF, it's the best thing I can do.

不幸的是,我只能指出你可能出现问题的地点和想法。考虑到JSF的大量选择,这是我能做的最好的事情。

#1


Which JSF (JavaServer Faces) library is this using? MyFaces? RichFaces? Something different?
I don't know if you've found this resource yet: JSF Tag lib. If it's using <ui: type tags, then it's also using Facelets which is a templating system for JSF. However the tag parameter you are probably looking for is styleClass and Style.

这个使用哪个JSF(JavaServer Faces)库? MyFaces的? RichFaces的?有些不同?我不知道你是否找到了这个资源:JSF Tag lib。如果它使用 标签,那么它也使用facelets,它是jsf的模板系统。但是,您可能正在寻找的tag参数是styleclass和style。

There really isn't a default styling for standard JSF, and I think there's probably another JSF library that's being used. Under the WEB-INF directory is probably a directory called lib where the jar files are. Those should give you a clue as to what library's are being used.

确实没有标准JSF的默认样式,我认为可能还有另一个正在使用的JSF库。在WEB-INF目录下可能是一个名为lib的目录,其中包含jar文件。那些应该给你一个关于什么库使用的线索。

RichFaces comes with its own styling, and is completely themeable. In your particular case, it's going to be more of a pain than it's worth for your situation. Other JSF library's may do the same.

RichFaces拥有自己的造型,完全可以打造主题。在你的特殊情况下,它会比你的情况更值得痛苦。其他JSF库也可以这样做。

Unfortunately I can only point you at places and ideas of where the problem might be. Given the vast number of choices when it comes to JSF, it's the best thing I can do.

不幸的是,我只能指出你可能出现问题的地点和想法。考虑到JSF的大量选择,这是我能做的最好的事情。