Richfaces Calendar Today Date - calendar

I am trying to change the "today" date in richfaces calendar module. I could not find anything in the CalendarDataModel provided by richfaces thus im trying to find the answer here. I am not talking about the selected date.
Use Case:
I am opening the calendar by clicking on the input and instead of current day and the preselected current month I want to get displayed November the 14th.
Wider explanation:
I have two different inputs which depend on each other. The date selected in the first input should be the "today" date in the second input.
Thank you for any suggestions.

Following code sets date from first calendar to second and rerender second calendar component. Code not sets today date for second calendar. System date is used as today date and it is the same date for first and second calendars. Code:
<h:panelGrid columns="2">
<h:outputLabel for="from" value="From" />
<rich:calendar id="from" value="#{t1Calendar.from}"
datePattern="dd/MM/yyyy" enableManualInput="true">
<a4j:ajax event="change" render="to"/>
</rich:calendar>
<h:outputLabel for="to" value="To" />
<rich:calendar id="to" value="#{t1Calendar.to}"
datePattern="dd/MM/yyyy" enableManualInput="true" popup="true"/>
</h:panelGrid>
and
#ManagedBean
public class T1Calendar {
private Date from = new Date();
private Date to;
public Date getFrom() { return from; }
public void setFrom(Date from) {
this.from = from;
this.to = from;
}
public Date getTo() { return to; }
public void setTo(Date to) { this.to = to; }
}

Related

Full Calendar 4.x for the Vaadin Framework 14+ not displaying in 24 hours format

enter image description here I have created a FullCalendar, it is displaying the time in AM/PM. When I am adding the enteries to the calendar, I format the LocalDateTime to 24 hours format but the Calendar displays it in AM/PM format.
How I can display the Calendar entries in 24 hours format?
My Formatter is defined as:
public static final DateTimeFormatter TWENTY_FOUR_HOURS_DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern("dd-MMM-yyyy HH:mm:ss", AppConstants.APP_LOCALE);
Entry entry = new Entry();
entry.setEditable(false);
entry.setTitle(game.getHomeClub() + " - " +game.getHomeTeam());
Instant now = Instant.now();
String t = LocalDateTime.of(game.getGameTime().toLocalDate(), game.getGameTime().toLocalTime())
.format(FormattingUtils.TWENTY_FOUR_HOURS_DATE_TIME_FORMATTER);
entry.setStart(calendar.getTimezone().convertToUTC(LocalDateTime.parse(t, FormattingUtils.TWENTY_FOUR_HOURS_DATE_TIME_FORMATTER)));
entry.setEnd(game.getGameTime().plus(2, ChronoUnit.HOURS));
calendar = new MyFullCalendar();
calendar.setWeekNumbersVisible(true);
calendar.setNowIndicatorShown(false);
calendar.setNumberClickable(true);
calendar.changeView(CalendarViewImpl.AGENDA_WEEK);
calendar.setLocale(Locale.GERMANY);
private void createTimedEntry(FullCalendar calendar, String title, String start, int minutes, String color) {
Entry entry = new Entry();
setValues(calendar, entry, title, start, minutes, ChronoUnit.MINUTES, color);
calendar.addEntry(entry);
}
You need to set the Locale.
#Route(value = "test")
class TestView extends Composite<Div> {
TestView() {
Locale defaultLocale = Locale.GERMANY
FullCalendar calendar = FullCalendarBuilder.create().build()
calendar.changeView(CalendarViewImpl.TIME_GRID_DAY)
calendar.setSizeFull()
RadioButtonGroup<Locale> localeSwitcher = new RadioButtonGroup()
localeSwitcher.setItems([defaultLocale, Locale.US])
localeSwitcher.addValueChangeListener({ ev ->
calendar.setLocale(localeSwitcher.value)
})
localeSwitcher.setValue(defaultLocale)
VerticalLayout layout = new VerticalLayout(localeSwitcher, calendar)
layout.setSizeFull()
content.add(layout)
}
}
Code (Groovy) above produces following calendar for German Locale:
and this for US Locale:
I know, the question is a bit old, but this answer may help anyone who is still searchting for an answer :)
Regardless of any i18n settings, you may use initial options on the server side to modifiy the event time format.
JsonObject initialOptions = Json.createObject();
JsonObject eventTimeFormat = Json.createObject();
//{ hour: 'numeric', minute: '2-digit', timeZoneName: 'short' }
eventTimeFormat.put("hour", "2-digit");
eventTimeFormat.put("minute", "2-digit");
eventTimeFormat.put("meridiem", false);
eventTimeFormat.put("hour12", false);
initialOptions.put("eventTimeFormat", eventTimeFormat);
FullCalendar calendar = FullCalendarBuilder.create()
.withInitialOptions(defaultInitialOptions)
// ...
.build();
Any initial options you can use you may obtain from the native library docs: https://fullcalendar.io/docs/eventTimeFormat (and other pages)

How to black out specific days of the week (datepicker) [VB]

I was wondering if it is possible to make particular days unavailable from the calendar (DatePicker), more specifically every Monday and Tuesday. I have found similar threads (How do create a DatePicker with only Sundays enabled? and Disable specific days of the week on jQuery UI datepicker) about blacking out dates, however, I have not been able to modify their code for my specific goal. I'm writing this application in VB.NET (WPF).
The functions I used so far, for blacking out dates are:
Datepicker1.BlackoutDates.AddDatesInPast()
Datepicker2.BlackoutDates.Add(New CalendarDateRange(DateTime.Now.AddDays(1), DateTime.MaxValue))
Where the first function will blackout the past-dates, and the second will black out all future dates. Because there is a 'DateRange' required for the second function, I'm not able to alter this function for my need.
Thanks in advance
Jerry
I modified one of the examples and came up with this.
It worked for me.
private void MyDatePicker_CalendarOpened(object sender, RoutedEventArgs e)
{
MyDatePicker.DisplayDateStart = DateTime.Now;
MyDatePicker.DisplayDateEnd = DateTime.Now + TimeSpan.FromDays(1000);
var minDate = MyDatePicker.DisplayDateStart ?? DateTime.MinValue;
var maxDate = MyDatePicker.DisplayDateEnd ?? DateTime.MaxValue;
for (var d = minDate; d <= maxDate && DateTime.MaxValue > d; d = d.AddDays(1))
{
if (d.DayOfWeek == DayOfWeek.Monday || d.DayOfWeek == DayOfWeek.Tuesday)
{
MyDatePicker.BlackoutDates.Add(new CalendarDateRange(d));
}
}
}
And here's a bonus: Prevent Certain Dates from Being Selected.
Thank you Okuma Scott, that was some helpful feedback! I rewrote your bit of code to VB language and according to my specific needs.
The included code will check all days in the next year, and will black out all the Mondays and Tuesdays.
Private Sub Datepicker_CalendarOpened(sender As Object, e As RoutedEventArgs) Handles Datepicker.CalendarOpened
Dim currDate As Date = DateTime.Now
Dim maxDate As Date = DateTime.Now.AddDays(356)
While (currDate < maxDate)
If currDate.DayOfWeek = DayOfWeek.Monday Or currDate.DayOfWeek = DayOfWeek.Tuesday Then
DatumSelectie.BlackoutDates.Add(New CalendarDateRange(currDate))
End If
currDate = currDate.AddDays(1)
End While
End Sub

App-engine query

I am new to app-engine Datastore and to NoSQL world in common. I am developing a simple application where a user can declare his/her expenses everyday. Every user(Account) has its own declared expenses. The dash board contains a simple GWT Cell Tree which contains all the years in which the use declared expenses and when he/she clicks on a years, he gets all the months of the years then he clicks on the month and he gets all the days of the month and finally clicking on a day and he gets all the expenses declared in that day. It is something like
*2010
|_ jan
|_1
|_2
|_Food 12d
|_Dress 200d
|_Fun 150d
|_ ...
|_ feb
|_ ...
*2011
|_ jan
|_ feb
|_...
I save expenses entities in the data store for each user(Account) as the account the parent of all the expenses. my expense is as follow:
public class Expense implements Serializable, Comparable {
private String name;
private double price;
private Date date;
public Expense(String name, double price, Date date) {
this.name = name;
this.price = price;
this.date = date;
}
public Expense() {
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
public boolean isPriceValid() {
return price > 0;
}
public void setName(String name) {
this.name = name;
}
public void setPrice(double price) {
this.price = price;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
#Override
public int compareTo(Expense expense) {
if (name.equals(expense.getName())) {
if (date.equals(expense.getDate())) {
return new Double(price).compareTo(expense.getPrice());
}
return date.compareTo(expense.getDate());
}
return name.compareTo(expense.getName());
}
My QUESTION IS: How to query the expenses in the data store and return all different years relater to a specified Account and put them in a list or set or anything else where I can list them ? does I need to fetch all the expenses entities and iterate over them and get all the different years. doesn't sound reasonable. Any advice will be welcome and THANKS IN ADVANCE.
Several comments related to your post :
--> I wouldn't store a financial amount as a Double. Going that route will lead you to big problems with rounding errors. There are a lot of posts on this one. I would suggest you to store it as "DollarCent" and declare it as an integer. You simply multiply the amount by 100 when you store it and when displaying it you divide by 100.
--> Why do you declare your entity in the Datastore as implementing Serializable ? I would store without Serializable.
--> Related to the specific question on displaying the data by year, reading your question I see no other way than fetching the data. What I would do is ask GAE to order the data to avoid having to order it afterwards. Using Objectify, it would simply be q.filter(...).order(-date).order(amount).
Hope this helps !
Hugues

format datetimepicker in datagridview column

I am trying to use the DateTime picker custom gridview column type from this MSDN example on How to host controls in DataGridViewCells. I want to display hour and minute in 24 hour format, without seconds or AM PM indicators.
I have set EditingControlFormattedValue to "HH:mm", and when not actually editing the value is displayed correctly.
When editing, if in the constructor of the CalendarEditingControl I set the editing control to CustomFormat = "HH:mm", the control displays the day of week and month. (!?)
When I instead use Format = DateTimePickerFormat.Time, the control shows AM or PM when editing.
How can I persuade this control to display only the parts of the DateTime value that I care about? (C#, VS 2008)
There are a few tweaks you need to to do the linked code to make it work the way you want:
Comment out the hard-coded line in CalendarCell() constructor (this.Style.Format = "d";)
Tell the CalendarEditingControl to use your custom-specified format:
In the designer, set the format you want (EditColumns->DefaultCellStyle->Format)
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
this.Format = DateTimePickerFormat.Custom;
this.CustomFormat = dataGridViewCellStyle.Format;
// ... other stuff
}
I found I needed to make the following changes:
In the constructor of the CalendarCell change the format to 24 hour.
public CalendarCell()
: base()
{
// Use the 24hr format.
//this.Style.Format = "d";
this.Style.Format = "HH:mm";
}
In the constructor for the editing control specify to use a custom format. I've also taken the liberty of setting ShowUpDown true so you don't show the calendar icon when editing the cell:
public CalendarEditingControl()
{
//this.Format = DateTimePickerFormat.Short;
this.Format = DateTimePickerFormat.Custom;
this.CustomFormat = "HH:mm";
this.ShowUpDown = true;
}
Change EditingControlFormattedValue. This doesn't appear to actually be necessary but feels icky to leave as is.
// Implements the IDataGridViewEditingControl.EditingControlFormattedValue
// property.
public object EditingControlFormattedValue
{
get
{
//return this.Value.ToShortDateString();
return this.Value.ToString("HH:mm");
}
set
{
if (value is String)
{
try
{
// This will throw an exception of the string is
// null, empty, or not in the format of a date.
this.Value = DateTime.Parse((String)value);
}
catch
{
// In the case of an exception, just use the
// default value so we're not left with a null
// value.
this.Value = DateTime.Now;
}
}
}
}

Is there a way to apply a mask to the textbox of a DatePicker?

I'm working on my first WPF app. In this case, using VS 2010. My users are used to typing the date like this: "09082010" (without the double quotes; this would represent today). After they enter that, then it gets converted to 9/8/2010. I've put the DatePicker control onto the WPF page, but if the user enters 09082010, then it doesn't recognize it as a date and ignores it. I've applied a IValueConverter, to no effect, again because it doesn't recognize "09082010" as a date. So, I'm wondering, is it possible to apply a mask to the textbox of the DatePicker in VS 2010, so that when a user enters 09082010 it will change that to 09/08/2010 (at least)?
Here's something you could probably do: handle the TextBox.TextChanged event in the DatePicker, then in the event handler, put your custom logic to parse the current text. Something like this:
<DatePicker x:Name="dp" TextBoxBase.TextChanged="DatePicker_TextChanged"/>
private void DatePicker_TextChanged(object sender, TextChangedEventArgs e)
{
DateTime dt;
DatePicker dp = (sender as DatePicker);
string currentText = (e.OriginalSource as TextBox).Text;
if (!DateTime.TryParse(currentText, out dt))
{
try
{
string month = currentText.Substring(0,2);
string day = currentText.Substring(2,2);
string year = currentText.Substring(4,4);
dt = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day));
dp.SelectedDate = dt;
}
catch (Exception ex)
{
dp.SelectedDate = null;
}
}
}
I know it ain't pretty. But this could be a start.

Resources