Wep0n
Wep0n

Reputation: 402

Primefaces calendar not firing dateSelect

I'm trying to get a value from my calendar via ajax.

xhtml portion:

<p:calendar
    id="newSimFrom"
    value="#{SimModel.from}" <!-- this works -->
    showOn="button"
    mask="true"
    pattern="dd.MM.yyyy"
>                       
    <p:ajax event="dateSelect" process="@this" update="newSimUnt" listener="#{SimController.simFromChanged()}" />
</p:calendar>

controller:

public void simFromChanged(SelectEvent se) {
    log.info("called");
    log.info(""+se.getObject()); 
    //this is temporary till I can figure out what's even going on
}

But I get nothing, no event seems to be fired. I've also tried event="change" as well as event="select" and process="@this" (latter as suggested by https://stackoverflow.com/a/42295586)

Also, I've tried to put the listener on with and without the parenthesises, didn't seem to make any differences.

The calendar is inside a form tag. (Kinda, there's 2 layers if <div> above, does that make a difference?) (https://stackoverflow.com/a/17213127/7591918)

Any ideas where I should go to for debugging what's going on? I'm relatively new to Primefaces and JSF as a whole, my IDE's console and my browser console don't give me any errors.

Thanks!

Upvotes: 0

Views: 1498

Answers (4)

jlbofh
jlbofh

Reputation: 442

In PF13 you dont need to specify a dateSelect ajax event and a listener, the "value" attribute gets the new date selected. If you dont specify the "value" attribute the listener method in <p:ajax is invoked succesfully.

So if you want your listener method to be invoked then remove the "value" attribute like this

<p:calendar
   id="newSimFrom"
   showOn="button"
   mask="true"
   pattern="dd.MM.yyyy">                       
      <p:ajax event="dateSelect" process="@this" update="newSimUnt" listener="#{SimController.simFromChanged()}" />
</p:calendar>

If you need to set an initial value, then use:

<p:calendar
   id="newSimFrom"
   showOn="button"
   mask="true"
   value="#{SimModel.from}"
   pattern="dd.MM.yyyy">                       
      <p:ajax event="dateSelect"  process="@this" update="newSimUnt" />
</p:calendar>

...it keeps your "SimModel.from" value updated.

Upvotes: 0

Wep0n
Wep0n

Reputation: 402

So Apparently, my problem was with how Spring internally addresses classes, or rather how the automatic name generation works, as I did not explicitly name the bean.

listener="#{SimController.newSimFromChanged}"

was changed to

listener="#{simController.newSimFromChanged}"

(note the lowercase s)

And now it works.

This is pretty unintuitive (IMO), and I'm not sure this is universally applicable but I'm going to leave this here if someone else ever has the same problem. Do note that this also does not apply if your class starts with multiple uppercase letters, if I had named my class SIMController it would have worked right away.

Upvotes: 0

ℛɑƒ&#230;Ŀᴿᴹᴿ
ℛɑƒ&#230;Ŀᴿᴹᴿ

Reputation: 5356

Wep0n, try these examples:

<p:calendar id="newSimFrom" value="#{SimModel.from}"
            showOn="button" mask="true" pattern="dd.MM.yyyy">

            <p:ajax event="dateSelect" update="newSimUnt" 
                    listener="#{SimController.simFromSelected}" />

            <f:ajax event="change" execute="@this" render="newSimUnt" 
                    listener="#{SimController.simFromChanged}"/>
</p:calendar>

And inside your managedBean SimController:

public void simFromSelected(DateSelectEvent event) {
    System.out.println("DateSelectEvent " + event.getDate());
}

public void simFromChanged(AjaxBehaviorEvent event) throws MWSException {
    System.out.println("AjaxBehaviorEvent " + event.getDate());
}

Upvotes: 0

lastresort
lastresort

Reputation: 552

The method in your listener isn't spelled correctly. You forgot the "new".

If you want to get the event don't use parentheses.

The event you get is a DateSelectEvent, so this should work:

xhtml:

<p:ajax event="dateSelect" process="@this" update="newSimUnt" listener="#{SimController.newSimFromChanged}" />

controller:

public void newSimFromChanged(DateSelectEvent se) {
    log.info("called");
    log.info("" + se.getDate()); 
    //this is temporary till I can figure out what's even going on
}

If that doesn't work the error must be somewhere else.

Upvotes: 0

Related Questions