calendar: auto set datetime on focus

UI Components for JSF
javaone9
Posts: 317
Joined: 06 Nov 2012, 20:50

09 Apr 2013, 01:34

Hello, when <p:calendar> get focus, it is automatically set the current time.(timestamp). This is not what we want.
If the date type is not timestamp(such as 01/12/2013), it value is not automatically set on focus.

Code: Select all

<p:calendar value="#{bean.value}"                     
                        mode="popup"
                        pattern="MM/dd/yyyy"
                        pagedate="#{bean.currentTime}"
                        showButtonPanel="true" navigator="true"
                        readonlyInput="false">  
Anything I can do to prevent <p:calendar> from auto setting values on focus? Thanks.
Dave

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

09 Apr 2013, 11:09

Yes, simply set the value in your bean currentTime property.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

HariMandala
Posts: 29
Joined: 26 Aug 2012, 19:24

10 Apr 2013, 00:42

Hi,
I am facing the exact same issue and I have been searching for a long time to find out what am I doing wrong in my code.
(I know I am doing wrong because I cannot replicate the same behavior in showcase example for Calendar, FYI)

I am Using Primefaces 3.4 and Mojarra 2.1.9.

Here is the code

Code: Select all

<h:panelGrid id="datesPanelGrid" columns="2">
						<b>Start Date:</b>
						<p:calendar id="selectBeginDate" value="#{gpsMessagesView.beginDate}"
							readOnlyInputText="true" navigator="true"
							pattern="MM/dd/yyyy HH:mm:ss">
							 						</p:calendar>

						<b>End Date:</b>
						<p:calendar id="selectEndDate" value="#{gpsMessagesView.endDate}"
							readOnlyInputText="true" navigator="true"
							pattern="MM/dd/yyyy HH:mm:ss">
						</p:calendar>
					</h:panelGrid>
My backing bean code

Code: Select all

........
private Date beginDate;
private Date endDate; 
.........

.........
public Date getBeginDate() {
		return beginDate;
	}

public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

public Date getEndDate() {		
		return endDate;
	}
public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
............
Issue: As soon as I click in the "inputText" box for p:calendar, it auto populates "today's date 00:00:00" for the first time. This however is not true when we manually "delete" the "auto populated date/time", (click somewhere else on the page) then come back and click in the "inputText" box for p:calendar the second time. Is the explanation clear? I hope so. If not let me know and I can explain it further.

I believe this behavior is caused by the "javascript", since anything being done in the backing bean is not influencing the outcome of the p:calendar. It is just a guess. I am not good with Javascript.

@Andy (or anyone else viewing this post),
Can you tell me if it is a bug in 3.4? FYI, this behavior doesn't happen in the showcase example, which, I believe, is currently running on primefaces 3.5.

@Javaone9,
Were you able to find any solution to this problem?
Primefaces 3.4
Mojarra 2.1.9

javaone9
Posts: 317
Joined: 06 Nov 2012, 20:50

10 Apr 2013, 07:50

The showcase works. I have not got a chance to try the new version, beta.
Keep sharing your experiment. Thanks.

javaone9
Posts: 317
Joined: 06 Nov 2012, 20:50

10 Apr 2013, 07:52

andyba wrote:Yes, simply set the value in your bean currentTime property.
we want it to be empty unless user selects a date/time.

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

10 Apr 2013, 09:48

javaone9 wrote:
andyba wrote:Yes, simply set the value in your bean currentTime property.
we want it to be empty unless user selects a date/time.
Ok, your first post was somewhat confusing, I assumed you wanted a date set by default.

You don't want any date value set which should be way things happen by default and is what happens with both the showcase and places in my own apps where p:calender is used and I have never seen this phenomenon.

Are you sure you are keeping the value of bean.currentTime null before a Date is selected?
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

javaone9
Posts: 317
Joined: 06 Nov 2012, 20:50

10 Apr 2013, 17:12

Yes. It is null before it gets focus. I am using 3.4.2. Which version do you use? Thanks.

HariMandala
Posts: 29
Joined: 26 Aug 2012, 19:24

11 Apr 2013, 00:09

:D Hi again,
The issue that I explained in my above post can be replicated (from the current showcase). Please read my above post again and then follow the steps below.

1) Go to primefaces showcase.
2) Click Calendar component.
3) Click on "TimePicker" from the dropdown
4) Click in "Min/Max" input box.

You should see today's date auto populated in the input box. I am facing exactly the same scenario.

Note: All must have noticed by now that you will not see the same behavior by clicking in the other "timepicker" input boxes. If you haven't, please do. Some may have different browser (or a different version) and might not observe the behavior explained.

Browser I used: IE 8

My Question: I have an ajax "DateSelect" listener on my calendar component and it will not be called in the scenario when user clicks in the input box but decides not to select any particular date. Now, can someone tell me how can I avoid such a scenario? Is it something related to javascript? (Sorry I had to ask again :) I have no clue how to work with it currently.)

Primefaces Calendar by the way.... a great component.... Kudos to everyone who worked on it. :P
Primefaces 3.4
Mojarra 2.1.9

HariMandala
Posts: 29
Joined: 26 Aug 2012, 19:24

12 Apr 2013, 16:42

HariMandala wrote: The issue that I explained in my above post can be replicated (from the current showcase). Please read my above post again and then follow the steps below.

1) Go to primefaces showcase.
2) Click Calendar component.
3) Click on "TimePicker" from the dropdown
4) Click in "Min/Max" input box.

You should see today's date auto populated in the input box. I am facing exactly the same scenario.
Did someone notice the above behavior in the showcase using IE8? Just curious. Hope its not something internal with our company's IE settings. Let me know.

If you know a way to solve (i.e to not auto populate today's date), do let everyone know. Thanks Hari.
Primefaces 3.4
Mojarra 2.1.9

HariMandala
Posts: 29
Joined: 26 Aug 2012, 19:24

16 Apr 2013, 22:34

I have created an issue in the issue tracker. Please star it, if you have faced this issue.
https://code.google.com/p/primefaces/is ... il?id=5479
(BTW, this issue is replicatable in current showcase examples as well. Please see my previous posts)

P.S. I have made a mess of issue 5478 because it was my first time creating an issue in the issue tracker. If anybody has rights to delete an issue in the issue tracker, please go ahead and delete it. Sincere apologies for any inconvenience.
Primefaces 3.4
Mojarra 2.1.9

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests