Ammar
Ammar

Reputation: 1821

How to bind a Date with calendar control in primefaces using binding attribute?

I want to bind a date with a calendar control after a specific value is selected from an autocomplete. But the following exception occurs : javax.servlet.ServletException: java.util.Date cannot be cast to javax.faces.component.UIComponent

<p:autoComplete value="#{rechargeCustomerBean.school.schoolName}" completeMethod="#{rechargeCustomerBean.completeSchool}" required="true" />

<p:calendar mode="popup"
        navigator="true" pattern="dd-MM-yyyy" effect="fadeIn"
        showButtonPanel="true"
        binding="#{rechargeCustomerBean.school.expiryDate}" />

Upvotes: 0

Views: 3867

Answers (2)

Daniel
Daniel

Reputation: 37061

Are you sure you want to bind?

Use the value attribute instead.

Also, add <p:ajax to your calendar to update the calendar and you are ready to go. like this

<p:autoComplete value="#{rechargeCustomerBean.school.schoolName}" completeMethod="#{rechargeCustomerBean.completeSchool}" required="true">
    <p:ajax event="itemSelect" update="idOfCalendar" /> 
</p:autoComplete>

Change

binding="#{rechargeCustomerBean.school.expiryDate}" 

into

value="#{rechargeCustomerBean.school.expiryDate}"

so it will look like this

<p:calendar value="#{rechargeCustomerBean.school.expiryDate}" id="idOfCalendar"..... />

Upvotes: 2

Mango
Mango

Reputation: 660

use of binding attribute in <p:calender> might cause the problem...try chaging it with value=#{...}

also make sure your bean's "expiryDate" is of type Util.Date

hope this could resolve your problem..for detailed explanation see here

Upvotes: 0

Related Questions