Primefaces - Use an Object in the DefaultScheduleEvent <p:schedule> - input

I'm using the <p:shecule> and i want to know how can i interact or use this Object data DefaultScheduleEvent.
For example if i want to fill the calendar with more information or save different data than the String title, Date start, date End.
Right now i'm filling the calendar using a for. And it's working fine. But there are more related information that i want to show in the <p:dialog>.
This is the addition information that i want to save/show
for (TimeSheetEntity timeSheetEntity : listaReportesTS) {
String descripcion = timeSheetEntity.getProyectoE().getDescripcionProyecto();
Date fechaInicio = obtFechaHora(timeSheetEntity.getDiaLaboral(), timeSheetEntity.getHoraInicio());
Date fechaFinal = obtFechaHora(timeSheetEntity.getDiaLaboral(), timeSheetEntity.getHoraFin());
eventModel.addEvent(new DefaultScheduleEvent(descripcion, fechaInicio, fechaFinal));
}
How can i do it? and how can i save all this data and get the DefaultScheduleEvent recognize it?
Thank you!
EDIT 1:
I created a new class that extends DefaultScheduleEvent but still no luck. The event is only saved when i enter the title, the start date and the end date. If i enter any other value nothing happens, not even an error in the console.
public class Prueba extends DefaultScheduleEvent{
private AsignacionEntity proyecto;
private TipoActividadEntity actividad;
private boolean horaAlmuerzo;
private String desc;
private String incidente;
private float horasTrabajadas;
public Prueba() {
super();
}
public Prueba(String title, Date startDate, Date endDate) {
super(title, startDate, endDate);
}
//getters and setters
And in the bean:
private Prueba pruebaEvento = new Prueba();
In the view:
<h:outputText for="incidente" value="IM/ALM"/>
<p:inputText id="incidente" value="#{registroBean.pruebaEvento.incidente}" required="false" size="5"/>
Finally i tried with the Object data and set the value from the VO/DTO in the constructor but no luck again.
dse = new DefaultScheduleEvent();
dse.setData(new TimeSheetVO());

Related

Mudblazor DatePicker binding works one way only

I have been trying to bind mudblazor datepicker to a DateTime property using Date.
<MudDatePicker Label="Start Date" Date="#StartDate" />
<MudTextField Label="SelectedDate" #bind-Value="#StartDate" />
<MudText Typo="Typo.h3">Selected Date is: #StartDate</MudText>
#code
{
public DateTime StartDate { get; set; }
public string DateString { get; set; }
}
I have tried this code on their site and in visual studio
The code will update the Date Picker and my Text output when leaving the text field, this is normal behavior. However, I want to change the Text based on my selection of Date picker. I have tried binding to date and value. both don't reflect the selection I have made.
I have checked the documentation on their site and there is nothing on how to handle binding beyond what I am doing.
If any one knows how to bind Date picker in mudblazor please help.
Thanks
for anyone interested here is the answer:
A Date picker in Mudblazor will only bind to a nullable DateTime, and I have to use #bind-Date. So my sample code that should work looks like this:
<MudDatePicker Label="Start Date" #bind-Date="#StartDate" />
<MudTextField Label="SelectedDate" #bind-Value="#StartDate" />
<MudText Typo="Typo.h3">Selected Date is: #StartDate</MudText>
#code
{
public DateTime? StartDate { get; set; }
}
I was having a similar issue with MudDateRangePicker.
I found that I could use a nullable or a non-nullable DateRange variable but if I wanted to get the currently selected Start & End dates from a callback function, I would have to call the DateRangePicker.Close() method before I checked the dates.
Just FYI if anyone else is looking at this issue.

dbcontext.savechanges always saves default Value

I have a SQL-Azure database created with Entity Framework 6.1, Code-First.
The "datetime" field in my 'EmazeEvents' table was created like this:
datetime = c.DateTime(nullable: false, defaultValueSql: "GETUTCDATE()")
and defined like this in the code:
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
[Index]
public DateTime datetime { get; set; }
I understand this means that in case this field is omitted in insertion, it will get by default the insertion date, which indeed it does.
However, I am having trouble inserting rows that set this field. Although I set the value of the appropriate variable, it still writes to the database the default date.
Some code extractions:
EmazeEvents is defined like this:
public class EmazeEvents:DbContext
{
public EmazeEvents()
: base("EmazeEvent")
{ }
public DbSet<EmazeEvent> events { get; set; }
}
}
What I do is:
context = new EmazeEvents();
EmazeEvent e = new EmazeEvent();
// e.datetime does get the correct date
e.datetime = DateTime.ParseExact("2014-05-31T00:00:06.8900000", "O", CultureInfo.InvariantCulture);
context.events.Add(e);
context.SaveChanges();
The record written to the database has the current date-time, ignoring the one in e.datetime.
I found out that the problem was with the definition of the 'datetime' field. When I removed the:
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
It started letting me write other values than the default.

Event Time Issue in Ektron calendar

I created a calendar event with all day selected (10/24/2013) . Then i tried to pull the e.EventStart and e.EventEnd. My expected result was EventStart =10/24/2013 12.00.00 am and
EventEnd= 10/25/2013 12.00.00 am. But what am getting is EventStart =10/24/2013 12.00.00 am and EventEnd= 10/24/2013 12.00.00 am.
The same works fine when I try with e.EventStartUtc and e.EventEndUtc. But I dont want the utc format as I am trying to pull out the ektron time for the users.
If you use the Framework API, the WebEventData class has a property called IsAllDay. You could use this to trigger the display change. For example, you might not want to display start/end times at all if it's an All Day event and just show the date.
If you do need to have particular start/end times for all day events, you can easily extend the Ektron WebEventData object with extension methods.
public static class WebEventExtensions
{
public static DateTime GetDisplayStartDate(this WebEventData webEvent)
{
if (!webEvent.IsAllDay)
return webEvent.EventStart;
return new DateTime(webEvent.EventStart.Year, webEvent.EventStart.Month, webEvent.EventStart.Day);
}
public static DateTime GetDisplayEndDate(this WebEventData webEvent)
{
if (!webEvent.IsAllDay)
return webEvent.EventEnd;
return new DateTime(webEvent.EventEnd.Year, webEvent.EventEnd.Month, webEvent.EventEnd.Day, 23, 59, 59);
}
}
Then those methods will appear on the object.
var eventManager = new WebEventManager();
WebEventData webEvent = eventManager.GetItem(730);
if (webEvent.IsAllDay)
{
// do all-day stuff...
}
var start = webEvent.GetDisplayStartDate();
var end = webEvent.GetDisplayEndDate();

Apache Wicket DateTextField clear

I have a problem in my DateTextField in Wicket. I want to set it by default to nothing, null, so date can be choosed after someone picks it. But by default it sets value to current day. How to "clear" it so nothing is in this datetextfield? Here is my Datefield code:
DateField date_insert_date_from = new DateField("insert_date_from", new PropertyModel(this, "date")) {
/**
* Format date to yyyy-MM-dd pattern.
*/
#Override
protected DateTextField newDateTextField(String id, PropertyModel dateFieldModel) {
return DateTextField.forDatePattern(id, dateFieldModel, "yyyy-MM-dd");
}
};
form.add(date_insert_date_from);
As #kan says, you need to make sure the modelobject for the datefield is null.
Simple way to do so is:
DateField date_insert_date_from = new DateField("insert_date_from", new Model<Date>(null));
Now, if anyone enters a date into the datefield and submits the form, the Model will contain the chosen date and you can retrieve it by writing:
Date chosenDate = date_insert_date_from.getModelObject();
If you want to use a propertymodel, as you do, you need to make sure the object on which the propertymodel acts (this in your case) has a field capable of holding a date and getter/setter methods for that field.
In your case, this.date should be initialized with null and this should have
public Date getDate()
and
public void setDate(Date date)
methods.

How to Accept and add Categories to RequiredAttendees Appointments using Exchange Web Services

I’m using ExchangeService(ExchangeVersion.Exchange2010_SP1)
I want to Accept and add Categories to RequiredAttendees Appointments. To do this i need to find these Appointments.
My understanding in EWS is that on Save of an Appointment that has RequiredAttendees a new Meeting Request is created for each of the ‘required attendees’.
How can I access the Appointments that were created automatically for the ‘required attendees’? These are shown in the required attendees Calendars as Appointments, along with a Meeting Request.
I have managed to do a crude find on the Subject (steps below)
Connect to server as Organiser
Create Appointment
Set Subject
Add Required Attendee
Save Appointment
Connect to server as Required Attendee from step 4
Find Appointment that has Subject at step 3
Add Categories to Appointment at step 7
Update Appointment at step 7
Accept Appointment at step 7
And this does work, but concerned users will change the Subject.
I have tried adding an Extended Property and value to the Appointment created by the Organiser and then FindItems for the Extended Property value in the Appointments connected as the Required Attendee. This does not work.
Is there a preferred method for what I’m trying to accomplish?
Thank you
Private Shared ReadOnly m_organiserEmailAddress As String = "Organiser#test.com"
Private Shared ReadOnly m_eventIdExtendedPropertyDefinition As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, "EventId", MapiPropertyType.Long)
'--> start here
Public Shared Function SaveToOutlookCalendar(eventCalendarItem As EventCalendarItem) As String
If eventCalendarItem.Id Is Nothing Then
'new
Dim newAppointment = EventCalendarItemMapper.SaveNewAppointment(eventCalendarItem)
'set the Id
eventCalendarItem.Id = newAppointment.Id.UniqueId.ToString()
'accept the calendar item on behalf of the Attendee
EventCalendarItemMapper.AcceptAppointmentAsAttendees(newAppointment)
Return eventCalendarItem.Id
Else
'update existing appointment
Return EventCalendarItemMapper.UpdateAppointment(eventCalendarItem)
End If
End Function
Private Shared Sub ConnectToServer(Optional autoUser As String = "")
If autoUser = "" Then
_service.Url = New Uri(ExchangeWebServicesUrl)
Else
_service.AutodiscoverUrl(autoUser)
End If
End Sub
Private Shared Sub ImpersonateUser(userEmail As String)
_service.Credentials = New NetworkCredential(ImpersonatorUsername, ImpersonatorPassword, Domain)
_service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, userEmail)
End Sub
Private Shared Function SaveNewAppointment(eventCalendarItem As EventCalendarItem) As Appointment
Try
ConnectToServer(m_organiserEmailAddress)
ImpersonateUser(m_organiserEmailAddress)
Dim appointment As New Appointment(_service) With {
.Subject = eventCalendarItem.Subject}
'add attendees
For Each attendee In eventCalendarItem.Attendees
appointment.RequiredAttendees.Add(attendee.Email)
Next
'add categories
For Each category In eventCalendarItem.Categories
appointment.Categories.Add(Globals.GetEnumDescription(category))
Next
'add EventId = 5059 as an extended property of the appointment
appointment.SetExtendedProperty(m_eventIdExtendedPropertyDefinition, 5059)
appointment.Save(SendInvitationsMode.SendOnlyToAll)
Return appointment
Catch
Throw New Exception("Can't save appointment")
End Try
End Function
Private Shared Sub AcceptAppointmentAsAttendees(appointment As Appointment)
For Each attendee In appointment.RequiredAttendees
Try
ConnectToServer(attendee.Address.ToString())
ImpersonateUser(attendee.Address.ToString())
For Each a In FindRelatedAppiontments(appointment)
a.Categories.Add(Globals.GetEnumDescription(CalendarItemCategory.Workshop))
a.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone)
a.Accept(True)
Next
Catch
Throw
End Try
Next
End Sub
Private Shared Function FindRelatedAppiontments(appointment As Appointment) As List(Of Appointment)
Dim view As New ItemView(1000)
Dim foundAppointments As New List(Of Appointment)
view.PropertySet =
New PropertySet(New PropertyDefinitionBase() {m_eventIdExtendedPropertyDefinition})
'Extended Property value = 5059
Dim searchFilter = New SearchFilter.IsEqualTo(m_eventIdExtendedPropertyDefinition, 5059)
For Each a In _service.FindItems(WellKnownFolderName.Calendar, searchFilter, view)
If a.ExtendedProperties.Count > 0 Then
foundAppointments.Add(appointment.Bind(_service, CType(a.Id, ItemId)))
End If
Next
Return foundAppointments
End Function
Well one thing is for sure that there is nothing straight forward in the EWS.
I will be honest with that, that till the moment, I did not work with integrating from the interior calendar to the Exchange calendar, my experience is the opposite , which is get what in the exchange to the internal one.
Anyway after reading your code, I think you are almost there. However I suggest that you catch the appointments that reach to the attendee by using the Streaming Notifications it is not that hard!
So I would say the steps should be like this
Create the appointment
Apply The extended property thing ( I suggest to use the GUID instead of hard coded number) as follows
Create an extended property, and put guid for the appointment, and it wont change unless you made a copy from another appointment (after all it is just a property)
private static readonly PropertyDefinitionBase AppointementIdPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "AppointmentID", MapiPropertyType.String);
public static PropertySet PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, AppointementIdPropertyDefinition);
//Setting the property for the appointment
public static void SetGuidForAppointement(Appointment appointment)
{
try
{
appointment.SetExtendedProperty((ExtendedPropertyDefinition)AppointementIdPropertyDefinition, Guid.NewGuid().ToString());
appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone);
}
catch (Exception ex)
{
// logging the exception
}
}
//Getting the property for the appointment
public static string GetGuidForAppointement(Appointment appointment)
{
var result = "";
try
{
appointment.Load(PropertySet);
foreach (var extendedProperty in appointment.ExtendedProperties)
{
if (extendedProperty.PropertyDefinition.Name == "AppointmentID")
{
result = extendedProperty.Value.ToString();
}
}
}
catch (Exception ex)
{
// logging the exception
}
return result;
}
Catch the appointment with the StreamingNotificationEvent. In my opinion a good way to do that is to run both Organizer and Attendee in the same time and catch the appointments between them.
To see an example, I have posted an answer to a previous question Multiple impersonation-threads in Exchange Web Service (EWS) . Please vote for the answers of both posts (here and there) if you found my answers are useful.
I do not want to make you scared, but once you solve your current problem; if you want to continue with it will get more complicated. I could write down how I solved the meetings problem, but I do not see it straight forward at all so it might be better if you write your own.
Cheers