- This topic has 5 replies, 3 voices, and was last updated 18 years, 9 months ago by ess_stegra.
-
AuthorPosts
-
ess_stegraParticipantI have not been able to get style sheets to work with JavaServer Faces. This example is taken from the JSFLoginDemo tutorial.
<%@ page language="java" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSF 'userLogin.jsp' starting page</title> </head> <body> <f:view> <f:loadBundle basename="com.jsfdemo.MessageBundle" var="bundle"/> <h:form id="loginForm"> <table> <tbody> <tr> <td><h:outputText value="#{bundle.user_name_label}" /></td> <td> <h:inputText id="userName" value="#{UserBean.userName}" required="true"> <f:validateLength minimum="1" /> </h:inputText> </td> </tr> <tr> <td><h:outputText value="#{bundle.user_password_label}" /></td> <td> <h:inputSecret id="password" value="#{UserBean.password}" required="true"> <f:validateLength minimum="3" /> </h:inputSecret> </td> </tr> <tr> <td colspan="2"> <h:messages style="font-weight: bold; color: #FF0000;" /> </td> </tr> <tr> <td align="right" colspan="2"> <h:commandButton id="submit" action="#{UserBean.loginUser}" value="#{bundle.login_button_label}" /> </td> </tr> </tbody> </table> </h:form> </f:view> </body> </html>
The line
<h:messages style="font-weight: bold; color: #FF0000;" />
Prints any error messages out above the login button in bold red text. If I change the code to use a style sheet:
<%@ page language="java" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSF 'userLogin.jsp' starting page</title> <link rel="STYLESHEET" type="text/css" href="style_basic.css"> <style type="text/css"> <!-- @import "style_basic.css"; --> </style> </head> <body> <f:view> <f:loadBundle basename="com.jsfdemo.MessageBundle" var="bundle"/> <h:form id="loginForm"> <table> <tbody> <tr> <td><h:outputText value="#{bundle.user_name_label}" /></td> <td> <h:inputText id="userName" value="#{UserBean.userName}" required="true"> <f:validateLength minimum="1" /> </h:inputText> </td> </tr> <tr> <td><h:outputText value="#{bundle.user_password_label}" /></td> <td> <h:inputSecret id="password" value="#{UserBean.password}" required="true"> <f:validateLength minimum="3" /> </h:inputSecret> </td> </tr> <tr> <td colspan="2"> <h:messages errorClass="errors" /> </td> </tr> <tr> <td align="right" colspan="2"> <h:commandButton id="submit" action="#{UserBean.loginUser}" value="#{bundle.login_button_label}" /> </td> </tr> </tbody> </table> </h:form> </f:view> </body> </html>
style_basic.css has the following style defined:
.errors { font-family: Arial, sans-serif; font-size: 14pt; color: red; }
This seems to have no affect on the HTML displayed in the browser. Any error messages display in black, normal text. Am I doing something wrong or is this a bug?
Here is my system setup:
*** Date: Tue Mar 14 23:55:53 MST 2006*** System properties:
OS=WindowsXP
OS version=5.1
Java version=1.5.0_06*** MyEclipse details:
MyEclipse Enterprise WorkbenchVersion: 4.1.1 GA
Build id: 20060228-4.1.1-GA*** Eclipse details:
Eclipse SDKVersion: 3.1.2
Build id: M20060118-1600Eclipse Platform
Version: 3.1.2
Build id: M20060118-1600Eclipse RCP
Version: 3.1.2
Build id: M20060118-1600Eclipse Java Development Tools
Version: 3.1.2
Build id: M20060118-1600Eclipse Plug-in Development Environment
Version: 3.1.2
Build id: M20060118-1600Eclipse Project SDK
Version: 3.1.2
Build id: M20060118-1600Eclipse startup command=-os
win32
-ws
win32
-arch
x86
-launcher
C:\eclipse\eclipse.exe
-name
Eclipse
-showsplash
600
-exitdata
ac0_38
-vm
C:\WINDOWS\system32\javaw.exeThanks in advance for any help.
japherMembertry changing: –
<style type="text/css"> <!-- @import "style_basic.css"; --> </style>
to: –
<LINK REL="STYLESHEET" HREF="style_basic.css" TYPE="text/css">
japherMemberoops sorry, missed the fact that you have it in the line above.
rateotyMemberhello,
you should check the generated html source code. Is class=”errors” generated?
regards Jürgen
ess_stegraParticipantclass=”errors” is not being generated. Here is a sample generated error message:
<tr> <td colspan="2"> You have entered an invalid user name and/or password </td> </tr>
Regards,
Steven
ess_stegraParticipantI solved the problem! (With a little help from someone on the Sun JSF forum.)
First I had a path problem with my style sheet. I changed:<link rel="STYLESHEET" type="text/css" href="style_basic.css">
To:
<link rel="STYLESHEET" type="text/css" href="/JSFLoginDemo/style_basic.css">
The second problem was I needed to set the message severity to severe before errorclass=”errors” gets invoked.
In my UserBean class, I changed:FacesContext facesContext = FacesContext.getCurrentInstance(); FacesMessage facesMessage = new FacesMessage("You have entered an invalid user name and/or password"); facesContext.addMessage("loginForm", facesMessage);
To:
FacesContext facesContext = FacesContext.getCurrentInstance(); FacesMessage facesMessage = new FacesMessage("You have entered an invalid user name and/or password"); facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR); facesContext.addMessage("loginForm", facesMessage);
The login message is now flagged as an error and the errors class is used from the style sheet.
-
AuthorPosts