[Index]

Getting Started

# Description
NOTE: This is an example on how it can be done.
01 Your war file must import (including this one).
  • JHPropertiesTyped-[version].jar
02
  • Create servlet class "PropertyCollectionHandlingServlet" (or similar name) which must extend "AbstractPropertyCollectionHandlingServlet".
    • Override method "getPropertyCollection()", returns the PropertyCollection initialized in WebContext below.
    • Overtide method "getPropertyIndexURL(ServletContext)", The page url for the page which displays your properties.
      The servlet will redirect to this page when a change is made for a property.
      This could be "myproperties.jsp", see below.
  • Register "PropertyCollectionHandlingServlet" in "web.xml".
        
    <servlet-mapping>
    	<servlet-name>PropertyCollectionHandlingServlet</servlet-name>
    	<url-pattern>/PropertyCollectionHandlingServlet</url-pattern>
    </servlet-mapping>
      	
  • Remember the Url-Pattern you use will be used in later code.
    03
  • Create a "WebContext" class where you initialize your properties.
    	    
    @Override
    public void contextInitialized(ServletContextEvent context) {		
    	WebDemoProperties.getInstance(context.getServletContext());			
    }
    	
  • 04
  • Register the "WebContext" class in "web.xml".
        
    <listener>
    	<listener-class>dk.heick.properties.webdemo.WebContext</listener-class>
    </listener>    
        
  • 05 Have two small images illustrates when a property is either valid or invalid.
    06 In your CSS definition make 3 new ones.
    • .jhproperties_td_even: How to render even rows in a table.
    • .jhproperties_td_odd: How to render odd rows in a table.
    • .jhproperties_th: How to render a table header.
    07
  • Example - Make a jsp page "myproperties.jsp" (Remember in this case than the method "PropertyCollectionHandlingServlet.getPropertyIndexURL()" must return ".....myproperties.jsp" )

    The handling URL "PropertyCollectionHandlingServlet" is a reference to the URL pattern defined above. Remember to take ServletContext into consideration.

        	
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <HTML>
    <head>
    <link rel="stylesheet" type="text/css" href="css/stylesheet.css" title="Style">
    </head>
    <BODY>
    <%
    	WebDemoProperties collection = WebDemoProperties.getInstance();
    	String message = PropertyCollectionHandlingServlet.getCollectionMessage(request);
    	PropertyCollectionRenderer render = new PropertyCollectionRenderer("images/valid.png","images/invalid.png","PropertyCollectionHandlingServlet");
    	PropertyIORenderer renderIO = PropertyIORenderer("PropertyCollectionHandlingServlet");
    %>
    
    <h1>My Properties</h1>
    <% if (message!=null) { %>
    	<b>Message:</b><%=message%><br/><br/>
    <% } %>
    
    <%=renderIO.renderPropertyIO(request, collection) %>
    <br/><br/>
    <%=render.renderProperties(request, collection,false) %>
    <br/><br/>
    <%=render.renderUnknownProperties(collection)%>
    </BODY>
    </HTML> 	
    
  • 08
    • Make "commons-logging.properties"
    • Make your logging framework properties, ex log4j will be "log4j.properties"
    09 To have a readonly version of this, you only need to setup bullets 01, 03, 04, 05, 06.
    And your JSP will look like:
        	
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <HTML>
    <head>
    <link rel="stylesheet" type="text/css" href="css/stylesheet.css" title="Style">
    </head>
    <BODY>
    <%
    	WebDemoProperties collection = WebDemoProperties.getInstance();	
    	PropertyCollectionRenderer render = new PropertyCollectionRenderer("images/valid.png","images/invalid.png");
    	PropertyIORenderer renderIO = PropertyIORenderer();
    %>
    
    <h1>My Properties</h1>
    <% if (message!=null) { %>
    	<b>Message:</b><%=message%><br/><br/>
    <% } %>
    
    <%=renderIO.renderPropertyIO(request, collection) %>
    <br/><br/>
    <%=render.renderProperties(request, collection,false) %>
    <br/><br/>
    <%=render.renderUnknownProperties(collection)%>
    </BODY>
    </HTML>