Reputation: 121
Let's say you have an Online Form where you have to Register to vote:
<html>
<head>
</head>
<body>
<form>
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname"><br>
Address: <input type="text" name="address"><br>
City: <input type="text" name="city"><br>
State: <input type="text" name="state"><br>
Zip: <input type="text" name="zip"><br>
Phone Number: <input type="text" name="phone"><br>
Affiliation:<br>
<input type="radio" name="affil" value="demo">Democrat<br>
<input type="radio" name="affil" value="green">Green Party<br>
<input type="radio" name="affil" value="liber">Liberterian<br>
<input type="radio" name="affil" value="repub">Republican<br>
<input type="radio" name="affil" value="None">Unafiiliated<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Somewhere in the form I want to put the text
"Next Election: [Date Value]"
However I don't want to hardcode the date in HTML and instead want a date inserted into my web.xml file, and then have the HTML file reference that date.
However, I'm very inexperienced with XML and how it would connect with HTML. How would I create a date in XML then have the HTML file reference it?
Here's my current "web.xml" file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<!-- Tell faces what extension it should be using to find files. -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<!-- Turn on debugging for faces. -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- This section loads the servlet that process faces into your app. -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- This tells the server where to send requests for faces pages. -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Upvotes: 0
Views: 447
Reputation: 1157
You can it with the help of jsf implicit EL objects.
<context-param>
<description>Date to be shown</description>
<param-name>showDate</param-name>
<param-value>26/05/2014</param-value>
</context-param>
You can display in UI with the help of following EL expression
#{initParam['showDate']}
To get an idea about JSF implicit EL objects plz refer the following article
http://balusc.blogspot.in/2011/09/communication-in-jsf-20.html
Hope this helps!!!!
Upvotes: 2
Reputation: 431
Entries in web.xml :- Define context parameter as date in web.xml
<context-param>
<description>Registration Date.</description>
<param-name>registrationDate</param-name>
<param-value>02/02/2014</param-value>
</context-param>
JSP Changes :- read date in jsp as follows.
ServletContext context = pageContext.getServletContext();
String registrationDate = context.getInitParameter("registrationDate");
Upvotes: -1