Reputation: 351
I just started using PrimeFaces and cannot figure what is wrong with my code. It is exactly the same as the show case sample with the exception of the bean names. I looked at this site for answers without success.
PrimeFaces:
<p:calendar value="#{securityForecastReturnBean.date}"
mode="inline" onSelectUpdate="inputsGrowl"
selectListener="#{securityForecastReturnBean.handleDateSelect}"
required="true" />
Java Bean:
@Component
@Scope("request")
@ManagedBean
public class SecurityForecastReturnBean {
public void handleDateSelect(DateSelectEvent event) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, "Date Selected",
format.format(event.getDate())));
}
}
It should be really straightforward yet it is saying that my bean does not have this property??
Here is the exact error message:
javax.servlet.ServletException: /security_page.xhtml: The class 'com.ls.forecast.webui.beans.SecurityForecastReturnBean' does not have the property 'handleDateSelect'.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:325)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546)
com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:363)
com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
I am using PrimeFaces 2.2.1.
Any help would be greatly appreciated!
Upvotes: 2
Views: 1944
Reputation: 91
The source code example given in the PrimeFaces Showcase is wrong. The method should not be taking org.primefaces.event.SelectEvent, it should be taking org.primefaces.event.DateSelectEvent. A quick change to the source code example now looks like this:
public void handleDateSelect(DateSelectEvent event) {
FacesContext facesContext = FacesContext.getCurrentInstance();
SimpleDateFormat format = new SimpleDateFormat("d/M/yyyy");
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Date Selected", format.format(event.getDate())));
}
Upvotes: 0
Reputation: 351
I figured out my issue. It had to do with using the wrong namespace. I had to use http://primefaces.org/ui instead of the old one.
Upvotes: 3
Reputation: 10463
This looks like it might be an error in the documentation:
From the Primefaces Guide 2.2:
Ajax Selection Calendar supports instant ajax selection which means whenever a date is selected a server side selectListener can be invoked with an org.primefaces.event.DateSelectEvent instance as a parameter. Optional onSelectUpdate option allows updating other component(s) on page.
<p:calendar value="#{calendarBean.date}" onSelectUpdate="messages"
selectListener="#{calendarBean.handleDateSelect}" />
<p:messages id="messages" />
public void handleDateSelect(DateSelectEvent event) {
Date date = event.getDate();
//Add facesmessage
}
Programatically it seems to expect a property on the managed bean. You can try changing it to this and see if it makes a difference #{calendarBean.handleDateSelect()}
. Are you absolutely sure that you are not referencing handleDateSelect
elsewhere in the markup?
Upvotes: 0