Jigar Shah
Jigar Shah

Reputation: 67

Primefaces Calendar getDate

I need to use Primefaces Calendar's Client side API to getDate. Here is the sample code but it is not working. What am I doing wrong?

Primefaces 3.4.2, JSF 2.2, Glassfish 4

 <h:form id="calendarFormId">
        <p:calendar id="calendarId" mode="inline" value="#{eventController.eventUI.date}" widgetVar="calendarWidget">
        </p:calendar>
    </h:form>

    <script>
        var myDate = calendarWidget.getDate();
        alert(myDate);
    </script>

Thanks

Upvotes: 1

Views: 1721

Answers (1)

Aksel Willgert
Aksel Willgert

Reputation: 11557

Debuging your codesnippet in firefox got the following trace:

[13:24:47,383] ReferenceError: calendarWidget is not defined @ http://localhost:8080/labb1/index.xhtml:12

So drew the conclusion that the script is executed to early. One way to delay execution is to wait for page to be ready.

<script>
    jQuery(document).ready(function() {
        var myDate = calendarWidget.getDate();
        alert(myDate);
    });
</script>

see how-to-execute-javascript-after-page-load

Upvotes: 1

Related Questions