Fact: HTTP request parameters are of String
type.
So, logically, you've got to convert from Date
to String
while preparing and writing the HTTP request parameter before sending and convert from String
back to Date
while reading and parsing the incoming HTTP request parameter.
You're not clear as to how exactly you're preparing the URL, but given that you're obtaining the Date
as input by <h:inputText>
, I'll assume that you're trying to pass it as a parameter of a redirect URL in a backing bean action method. In that case, use SimpleDateFormat
to convert from Date
to String
.
public String submit() {
String dateString = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
return "newpage.xhtml?faces-redirect=true&date=" + dateString;
}
In the receiving page, newpage.xhtml
, you can use <f:viewParam>
to set it as a bean property. It uses SimpleDateFormat
under the covers, so you can use the same pattern syntax.
<f:metadata>
<f:viewParam name="date" value="#{bean.date}">
<f:convertDateTime pattern="yyyyMMddHHmmss" />
</f:viewParam>
</f:metadata>
See also: