marouanoviche
marouanoviche

Reputation: 253

how to get value of primefaces calendar in managed bean?

i have a calendar in my jsf page that i want to get his value when its changed i tryed to add listener but didnt work i found other solutions but didnt work with primefaces 3.5:

   <p:calendar id="popupButtonCal22" value="#{zp01ManagedBean.datedeplanification}" showOn="button" locale="fr"  >
<p:ajax listener="#{zp01ManagedBean.setDatedeplanification(zp01ManagedBean.datedeplanification)}"/>   
                </p:calendar>

do you know how to fixe this problem ?

i am using primefaces 3.5

Upvotes: 0

Views: 12526

Answers (5)

zety
zety

Reputation: 156

<p:calendar ...>
    <p:ajax event="dateSelect" ... />
    <p:ajax event="change" ... />
</p:calendar>

This works for me.

Upvotes: 0

user2672770
user2672770

Reputation: 51

  • <p:ajax partialSubmit="true"/>
    works with inputText.

  • <p:ajax event="dateSelect"/>
    works with calendar when is selected a date.

  • <p:ajax event="change"/>
    works with calendar when is typed a date.

Upvotes: 5

NDeveloper
NDeveloper

Reputation: 3177

Try This, May be this can Help:

<h:body>
    <h:form>
        <p:calendar id="dateObj" value="#{test.date1}" showOn="button" pattern="dd-MMMM-yyyy">
            <p:ajax event="dateSelect" listener="#{test.handleDateSelect}"/>
        </p:calendar>
    </h:form>
</h:body>

The Bean is like that:

private Date date1;
public Date getDate1() {
    return date1;
}

public void setDate1(Date date1) {
    this.date1 = date1;
}


public void handleDateSelect(DateSelectEvent event){

    System.out.println(event.getDate());
}

Upvotes: 0

Akheloes
Akheloes

Reputation: 1372

Try to put the p:calendar component in a h:form tag. I don't see why your code won't work actually, you do not even need ajax for that...

Upvotes: 0

user1983983
user1983983

Reputation: 4841

It is not necessary to set the value manually by an ajax listener, as the setter is implicitly called when the value of the field is submitted. All you have to do is to submit the value on change. So try this:

<p:calendar id="popupButtonCal22" value="#{zp01ManagedBean.datedeplanification}" showOn="button" locale="fr"  >
    <p:ajax process="popupButtonCal22" partialSubmit="true" event="change"/>   
</p:calendar>

If you would additionally like to call an action after the value changed you can add listener="#{someBean.someAction" to the p:ajax-tag.

And if you would like to do some checks with the old and the new value use the valueChangeListener-attribute of the p:calendar-tag.

Upvotes: 1

Related Questions