Typeerror: cannot read property getdate of undefined

UI Components for JSF

mrdodaPosts: 3Joined: 05 Apr 2016, 14:49

What is wrong?

Calendar component cant change date when it is set to something. Why? How to do it properly?

Simplest demo possible:

Controller:

Code: Select all

@ManagedBean
public class DateErrorExample {
	private Date date;
	
	public DateErrorExample(){
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.add(Calendar.MINUTE, -7);
		this.date = cal.getTime();
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
}

View:

Code: Select all

<h:body>
		<h:form>
			<p:calendar id="date-time"  value="#{dateError.date}" title="Choose Date" pattern="HH:mm:ss"  />
		</h:form>

</h:body>

When I click on it in the browser. It shows Cannot read property 'getDate' of null in Javascript console... And the popup DateTime Picker will not show up. What am I missing?

Typeerror: cannot read property getdate of undefined

version of primefaces: 5.3, Java 8, Server Wildfly 8.1.final

Thank you all


Miguel CubellsPosts: 99Joined: 25 Feb 2015, 11:02

06 Apr 2016, 16:06

If your managed bean is really defined like this:

Code: Select all

@ManagedBean
public class DateErrorExample

then your calendar value should be defined like this:

Code: Select all

<p:calendar id="date-time"  value="#{dateErrorExample.date}" title="Choose Date" pattern="HH:mm:ss"  />

Nothing to do with PrimeFaces, but basic JSF usage, I presume ...

PrimeFaces 6.1 / PF Extensions 6.1.1 / Atmosphere 2.4.3
Apache Mojarra 2.2.13+
WildFly 10.1.0.Final


mrdodaPosts: 3Joined: 05 Apr 2016, 14:49

10 Apr 2016, 11:56

Miguel Cubells wrote:If your managed bean is really defined like this:

Code: Select all

@ManagedBean
public class DateErrorExample

then your calendar value should be defined like this:

Code: Select all

<p:calendar id="date-time"  value="#{dateErrorExample.date}" title="Choose Date" pattern="HH:mm:ss"  />

Nothing to do with PrimeFaces, but basic JSF usage, I presume ...

Well this is not the problem. I have this in my faces-config.xml ->

Code: Select all

<managed-bean>
		<managed-bean-name>dateError</managed-bean-name>
		<managed-bean-class>com.timetracker.controller.DateErrorExample</managed-bean-class>
		<managed-bean-scope>application</managed-bean-scope>
	</managed-bean>

So it does connect to the right controller. It even shows the time on the website. but what doesnt work is when I click at the compponent, the poppup should show up, but the javascript error come instead.


rossdPosts: 18Joined: 26 Oct 2015, 06:51

11 Apr 2016, 05:18

I would suspect that the default scope of the managed bean is too short lived for the ajax update to work, so you should try making it ViewScoped for the length of the time you are looking at the page.

Ross.


tandraschkoPrimeFaces Core DeveloperPosts: 3927Joined: 03 Dec 2010, 14:11Location: Bavaria, DE Contact:

11 Apr 2016, 07:57

I'm also not sure if the name from @ManagedBean or the name defined in faces-config has a higher prio

Typeerror: cannot read property getdate of undefined


    • Who is online

      Users browsing this forum: Samantafpn and 11 guests

    Examples

    Get the day of the month:

    const d = new Date();
    let day = d.getDate();

    Try it Yourself »

    Get the day of a specific date:

    const d = new Date("July 21, 1983 01:15:00");
    let day = d.getDate();

    Try it Yourself »


    Definition and Usage

    The getDate() method returns the day of the month (1 to 31) of a date.


    Syntax

    Parameters

    Return Value

    Type Description
    A number The day of the month (1 to 31).


    Browser Support

    getDate() is an ECMAScript1 (ES1) feature.

    ES1 (JavaScript 1997) is fully supported in all browsers:

    Chrome IE Edge Firefox Safari Opera
    Yes Yes Yes Yes Yes Yes