How to pass java.util.Date to a url from a jsf page?

I need to pass java.util.Date to a url from a bean base to another Facelet (and bean).

Can someone tell me if this is possible? I know that I cannot pass complex objects to URLs, but does this also include Date?

Or do I need to convert the entered date (using the JSF tag <h:inputText>) to String, pass it to the URL and then convert it back?

+4
source share
1 answer

Fact: HTTP request parameters are of type String.

, , Date String HTTP- String Date HTTP- .

, URL-, , , Date <h:inputText>, , URL- bean. SimpleDateFormat Date String.

public String submit() {
    String dateString = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
    return "newpage.xhtml?faces-redirect=true&date=" + dateString;
}

newpage.xhtml <f:viewParam>, bean. SimpleDateFormat , .

<f:metadata>
    <f:viewParam name="date" value="#{bean.date}">
        <f:convertDateTime pattern="yyyyMMddHHmmss" />
    </f:viewParam>
</f:metadata>

. :

+10

All Articles