I have two DatePickers and one Button on the GUI. I need to disable the button whenever the first datePicker has a date that is NOT before the second datePicker's date. i.e. before is false in the following snippet:
LocalDate date1 = dpFromDate.getValue();
LocalDate date2 = dpToDate.getValue();
boolean before = date1.isBefore(date2);
button.setDisable(!before);
using Bindings APIs.
BooleanBinding bb = ???;
button.disableProperty().bind(bb);
Here is my working solution, but I believe there is a better API to handle such situation:
BooleanBinding bb = Bindings.selectInteger(dpFromDate.valueProperty(), "year")
.greaterThanOrEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "year"));
bb = bb.or(
Bindings.selectInteger(dpFromDate.valueProperty(), "year")
.isEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "year"))
.and(Bindings.selectInteger(dpFromDate.valueProperty(), "monthValue")
.greaterThanOrEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "monthValue")))
);
bb = bb.or(
Bindings.selectInteger(dpFromDate.valueProperty(), "year")
.isEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "year"))
.and(Bindings.selectInteger(dpFromDate.valueProperty(), "monthValue")
.isEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "monthValue")))
.and(Bindings.selectInteger(dpFromDate.valueProperty(), "dayOfMonth")
.greaterThanOrEqualTo(Bindings.selectInteger(dpToDate.valueProperty(), "dayOfMonth")))
);
Just create a BooleanBinding depending on the DatePicker values that compares both dates. This way you don't have to write the functionality yourself and even more important - you don't need to create such a complicated binding:
BooleanBinding bb = Bindings.createBooleanBinding(() -> {
LocalDate from = dpFromDate.getValue();
LocalDate to = dpToDate.getValue();
// disable, if one selection is missing or from is not smaller than to
return (from == null || to == null || (from.compareTo(to) >= 0));
}, dpFromDate.valueProperty(), dpToDate.valueProperty());
button.disableProperty().bind(bb);
Related
I tried to click on from-date textbox to select the From-Date but I am not able to do so for "opensource-demo.orangehrmlive.com". Dashboard > Apply leave
driver.findElement(By.id("applyleave_txtFromDate").click();
Select secMonth = new Select(driver.findElement(By.xpath("//div[#class='ui-datepicktitle']/select[1]")));
secMonth.selectByVisibleText("Jan"); Select secYear = new Select(driver.findElement(By.xpath("//div[#class='ui-datepicker-title']/select[2]")));
secYear.selectByVisibleText("2021");
java.util.List<WebElement> dates = driver.findElements(By.xpath("//td[#data-handler='selectDay']"));
int count = dates.size();
for(int i=0;i<count;i++)
{
String ReqD = dates.get(i).getText();
if(ReqD.equalsIgnoreCase("2"))
{
dates.get(i).click();
break;
}
it does not work?
String someDate = "2020-01-02";
WebElement fromDate = driver.findElement(By.id("applyleave_txtFromDate");
fromDate.click();
fromDate.sendKeys(someDate);
fromDate.sendKeys(Keys.TAB);
I would recommend for you to use AppConstants to add all final values to it. Then it will be easier to pass it using String
(example: public static final String DATE_VALUE = "12/22/2020";)
I use this approach for automation testing, because of you are going to use this script for long run as a regression testing for your framework, it will not pass when the calendar month will change. You will have to update your script. But if you will pass it within String value, your script will not need modifications.
I have object, this is describe of it?
public MemberSkills(User user, BasicSkills skills, Short level, Short status, LocalDateTime confirmDate, String comment) {
this.user = user;
this.skills = skills;
this.level = level;
this.status = status;
this.confirmDate = confirmDate;
this.comment = comment;
}
I want to filter MemberSkill by from "confirmDate" to "confirmDate".
I am using Java-8 & Java-springboot.
I tried, but it did not work.
LocalDateTime fromdate = LocalDateTime.parse(memberSkillRequest.getFromDate(), formatter);
LocalDateTime toDate = LocalDateTime.parse(memberSkillRequest.getToDate(), formatter);
List<MemberSkills> filterMemberSkill = memberSkills.stream().filter(memberSkill -> memberSkill.getConfirmDate().isBefore(fromdate)).collect(Collectors.toList());
List<MemberSkills> listMemberSkill = filterMemberSkill.stream().filter(memberSkill -> memberSkill.getConfirmDate().isAfter(toDate)).collect(Collectors.toList());
fromdate and todate get from client send up.
Probably because you are running second filtering on the first filtered list which already excluded anything comes out of the second filter. You should be able to do something like this -
List<MemberSkills> filterMemberSkill = memberSkills.stream()
.filter(memberSkill -> memberSkill.getConfirmDate().isBefore(toDate)
&& memberSkill.getConfirmDate().isAfter(fromDate))
.collect(Collectors.toList());
My guess is you intended this:
List<MemberSkills> listMemberSkill = memberSkills.stream()
.filter(memberSkill -> ! memberSkill.getConfirmDate().isBefore(fromdate))
.filter(memberSkill -> memberSkill.getConfirmDate().isBefore(toDate))
.collect(Collectors.toList());
This gives you the MemberSkills objects with confirmation dates in the half-open interval between from date and to date. That is, dates have to be on or after from date and strictly before to date. This is the common way to define time intervals. In the code I use “not before” to mean “on or after”.
#Override
public void onAccessibilityEvent(final AccessibilityEvent event) {
Date date = new Date(event.getEventTime());
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm");
String time = format.format(date);
String reqTime = "25/11/2018 04:39";
if (reqTime.equals(time)) {
Log.d("MyAccessibilityService", "onAccessibilityEvent");
if (getRootInActiveWindow() == null) {
return;
}
AccessibilityNodeInfoCompat rootInActiveWindow = AccessibilityNodeInfoCompat.wrap(getRootInActiveWindow());
//Inspect app elements if ready
//Search bar is covered with textview which need to be clicked
List<AccessibilityNodeInfoCompat> clickOnQuestionMark = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.whatsapp:id/menuitem_search");
if (clickOnQuestionMark.isEmpty() || clickOnQuestionMark == null) {
return;
}
AccessibilityNodeInfoCompat clickMark = clickOnQuestionMark.get(0);
clickMark.performAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
I am using this code for simuating clicking whatsapp search button, but when I opened whatsapp window on 25-11-2018 at 4:39 nothing happened. The code was working fine when no time was alloted. But problem was that everytime whatsapp was opened the search button would get clicked. How to click on the search button only when whatsapp is opened at a specific time?
You can convert to LocalDate
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
and use equals method to specific LocalDate
Compares this LocalDate with another ensuring that the date is the same.
Only objects of type LocalDate are compared, other types return false.
I have written the code as below where it deletes the Appointment having current date but is there a way where i can delete the entire Calendar Appointments in one shot. Thanks in Advance
epublic static HashSet<String> userEventEws(ExchangeService service) {
HashSet<String> listSubject = new HashSet<String>();
Calendar yesterday = Calendar.getInstance();
Calendar now = Calendar.getInstance();
yesterday.add(Calendar.DATE, -1);
now.add(Calendar.DATE, 1);
Date startDate = yesterday.getTime();
Date endDate = now.getTime();
try {
CalendarFolder calendarFolder = CalendarFolder.bind(service, WellKnownFolderName.Calendar, new PropertySet());
CalendarView cView = new CalendarView(startDate,endDate);
cView.setPropertySet(new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End));// we can set other properties
// as well depending upon our need.
FindItemsResults appointments = calendarFolder.findAppointments(cView);
List <Appointment>appList = appointments.getItems();
for (Appointment appointment : appList) {
listSubject.add(appointment.getSubject().trim());
appointment.delete(DeleteMode.HardDelete);
}
} catch (Exception e) {
e.printStackTrace();
}
return listSubject;
}
Generally the two options you have is you can batch delete the Items that you return from FindItems (find appointments will expand the recurring appointments which if you want to delete all the Items you don't want to do just delete the Master and single instances instead see https://msdn.microsoft.com/en-us/library/office/dn626016(v=exchg.150).aspx#bk_deleteews )
The other option would be to use the Empty Folder operation which should work in 2013 and above https://msdn.microsoft.com/en-us/library/office/ff709484%28v=exchg.150%29.aspx
I'm trying to implement FROM and TO Date validation in Oracle MAF form.
In ADF I have seen the tag some thing like <af:validateDateTimeRange minimum="" maximum=""/>. From this blog you can get more details, It can be implemented in ADF application.
But I could't find such tag in Oracle MAF. Can you please suggest me, if you got any link to support this requirement?
you would need to use a value change listener. There is no equivalent tag in MAF
Frank
As suggested by Frank, below is the workaround to achieve this.
AMX Page:
<amx:inputDate value="#{bindings.inspFromDate.inputValue}" label="From Date" showRequired="true" inputType="datetime" valueChangeListener="#{validationBean.dateValidation}"/>
<amx:inputDate value="#{bindings.inspToDate.inputValue}" label="To Date" showRequired="true" inputType="datetime" valueChangeListener="#{validationBean.dateValidation}"/>
ValidationBean.java
public void dateValidation(ValueChangeEvent valueChangeEvent) throws ParseException {
String fromDate = (String) AdfmfJavaUtilities.evaluateELExpression("#{bindings.inspFromDate.inputValue}");
String toDate = (String) AdfmfJavaUtilities.evaluateELExpression("#{bindings.inspToDate.inputValue}");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
formatter.setTimeZone(TimeZone.getTimeZone("IST"));
if (fromDate != null && !fromDate.isEmpty() && toDate != null && !toDate.isEmpty()) {
java.util.Date inputFromDate = formatter.parse(fromDate);
java.sql.Timestamp formattedFromDate = new Timestamp(inputFromDate.getTime());
java.util.Date inputToDate = formatter.parse(toDate);
java.sql.Timestamp formattedToDate = new Timestamp(inputToDate.getTime());
if (formattedFromDate.compareTo(formattedToDate) > 0) {
System.out.println("fromDate is greater than toDate");
throw new AdfException("From Date should be less than To Date.!", AdfException.INFO);
} else if (formattedFromDate.compareTo(formattedToDate) < 0) {
System.out.println("fromDate is less than toDate");
} else if (formattedFromDate.compareTo(formattedToDate) == 0) {
System.out.println("fromDate is equal to toDate");
}
}
}
This method will get both from date and to date from the front screen and convert into timestamp format to validate which is greater.
If From Date is greater than To Date, then it will show you the alert by saying that "From Date should be less than To Date.!". Below is the screenshot, how it will render in the front screen.
Hope this helps some one.!