Board index JavaServer Faces General calendar: auto set datetime on focus

calendar: auto set datetime on focus

Components, Ajax Framework, Utilities and More.


Posts: 283
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.
<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
JSF components: PrimeFaces 5.0
JSF core: Mojarra 2.2.6
Glassfish 4, Tomcat 8
FireFox 28, IE 8, Chrome 24.0

andyba User avatar
Expert Member

Posts: 2217
Location: Steinfeld, near Bremen/Osnabrück, DE

Yes, simply set the value in your bean currentTime property.
PF 3.4.2, PF 3.5.10, PF 4.x (Elite versions)
Glassfish 3.1.2.2, Mojarra 2.x, under both Java 6 and Java 7.
If you haven't read the forum rules read them now
My blog: http://onthefaceofthings.blogspot.de/
PrimeFaces Project


Posts: 29
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
<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
........
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


Posts: 283
The showcase works. I have not got a chance to try the new version, beta.
Keep sharing your experiment. Thanks.
JSF components: PrimeFaces 5.0
JSF core: Mojarra 2.2.6
Glassfish 4, Tomcat 8
FireFox 28, IE 8, Chrome 24.0


Posts: 283
andyba wrote:
Yes, simply set the value in your bean currentTime property.

we want it to be empty unless user selects a date/time.
JSF components: PrimeFaces 5.0
JSF core: Mojarra 2.2.6
Glassfish 4, Tomcat 8
FireFox 28, IE 8, Chrome 24.0

andyba User avatar
Expert Member

Posts: 2217
Location: Steinfeld, near Bremen/Osnabrück, DE

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 3.4.2, PF 3.5.10, PF 4.x (Elite versions)
Glassfish 3.1.2.2, Mojarra 2.x, under both Java 6 and Java 7.
If you haven't read the forum rules read them now
My blog: http://onthefaceofthings.blogspot.de/
PrimeFaces Project


Posts: 283
Yes. It is null before it gets focus. I am using 3.4.2. Which version do you use? Thanks.
JSF components: PrimeFaces 5.0
JSF core: Mojarra 2.2.6
Glassfish 4, Tomcat 8
FireFox 28, IE 8, Chrome 24.0


Posts: 29
: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


Posts: 29
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


Posts: 29
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

Next

Return to General