facebook

Proper Tag Library declaration using XML for JSFs

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

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

    Russ
    Member

    I wanted to bring to your attention a style difference involving how tag libraries are declared in JSF enabled files. It is common practice to declare tag libraries in this way using the following format for JSPs:

    
    <%@ page language="java" pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
        <base href="<%=basePath%>">
    
        <title>My JSF 'test.jsp' starting page</title>
        
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
    
    </head>
      
    <body>
        <f:view>
            This is my JSF JSP page. <br>
        </f:view>
    </body>
    </html>
     

    However, a JSF coding standard advocated by many industry leaders is JSF.

    
    <?xml version="1.0" ?>
    <jsp:root version="2.0"
              xmlns:jsp="http://java.sun.com/JSP/Page"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html">
    
    <jsp:directive.page contentType="text/html"/>
    <jsp:output omit-xml-declaration="no"
                doctype-root-element="html"
                doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
                doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
              
    <f:view>
        <html xmlns="http://www/w3/org/1999/xhtml">
              <head>
                <title>A Simple JavaServer Faces Application</title>
              </head>
      
              <body>
                <h:form>
                     ..............
                </h:form>
              </body>
        </html>
    </f:view>
    </jsp:root>
    

    The rationale behind such a difference is the style follows more of an XML standard while eliminating the <% ..%> tags. It also identifies the proper DOCTYPE declaration for the generated HTML document.

    The overall benefit of using this style is XML Editors will provide you more feedback in your design effort.

    I hope this helps.

    Russ

    #272467

    Loyal Water
    Member

    Hi Russ,
    Thanks for this post. I’ll take this to the development team.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Proper Tag Library declaration using XML for JSFs

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