facebook

Style Sheets Not Working With JSF

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #248598 Reply

    ess_stegra
    Participant

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

    Version: 4.1.1 GA
    Build id: 20060228-4.1.1-GA

    *** Eclipse details:
    Eclipse SDK

    Version: 3.1.2
    Build id: M20060118-1600

    Eclipse Platform

    Version: 3.1.2
    Build id: M20060118-1600

    Eclipse RCP

    Version: 3.1.2
    Build id: M20060118-1600

    Eclipse Java Development Tools

    Version: 3.1.2
    Build id: M20060118-1600

    Eclipse Plug-in Development Environment

    Version: 3.1.2
    Build id: M20060118-1600

    Eclipse Project SDK

    Version: 3.1.2
    Build id: M20060118-1600

    Eclipse 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.exe

    Thanks in advance for any help.

    #248608 Reply

    japher
    Member

    try changing: –

    
        <style type="text/css">
          <!--
          @import "style_basic.css";
          -->
       </style> 
    

    to: –

    
     <LINK REL="STYLESHEET" HREF="style_basic.css" TYPE="text/css">
    
    #248609 Reply

    japher
    Member

    oops sorry, missed the fact that you have it in the line above.

    #248610 Reply

    rateoty
    Member

    hello,

    you should check the generated html source code. Is class=”errors” generated?

    regards Jürgen

    #248660 Reply

    ess_stegra
    Participant

    class=”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

    #248916 Reply

    ess_stegra
    Participant

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

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Style Sheets Not Working With JSF

You must be logged in to post in the forum log in