Reputation: 153
I am writing a JSF 2.0 Mojarra application using Primefaces 3.3.1 on Tomcat 6. Using the PrimeFaces <p:calendar>
component, I need to disable future dates. I realize that I must set the maxdate attribute to the current date. However, I am not sure what the easiest way is to accomplish this.
I realize that I could create a Managed Bean of java.util.Date
, but this is an international application, and I need to account for the location of the user. If the user is on the other side of the world, the server date could be incorrect for him.
So, what is the easiest way to retrieve the current date at the user's location, and set the <p:calendar>
maxdate attribute equal to that value? A completely client-side solution would be ideal, if that is possible.
Upvotes: 1
Views: 11078
Reputation: 1
We can also use faces-config.xml to define currentDate bean
enter code here
<managed-bean>
<managed-bean-name>currentDate</managed-bean-name>
<managed-bean-class>java.util.Date</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Then use it in .xhtml
<p:calendar maxdate="#{currentDate}" />
Upvotes: 0
Reputation: 1
its more simple than that it disable all the past dates until the current day
Upvotes: -2
Reputation: 1043
As primefaces-chief Cagatay Civici already stated out you can use p:calendar
maxDate
for that reason. As I dont what to mix up my facelets with JS, here is the way I did it:
faclet:
<p:calendar maxdate="#{bean.today}" />
bean:
public Date getToday() {
return new Date();
}
So no future to be selectable.
Upvotes: 5
Reputation: 15350
You can get the client system date.
<p:calendar>
calendar is an jquery-ui widget, you can have client acess on it by defining widgetVar and set the maxdate using javascript.
<p:calendar widgetVar="myCalendar" />
<script type="text/javascript">
jQuery(document).ready(function(){
myCalendar.jqEl.datepicker("option", "maxDate", +0);//set maxDate to today
});
</script>
Upvotes: 0