I have a UIPanel that contains form elements. On click of submit, the form validates all the fields and if they are all valid, proceeds to insert the field values into the DB. If the DB returns a duplicate key exception, I show a message telling the user to update the field (See http://goo.gl/jOzZGG).
The message shows up, and the form loads properly for the most part, but a problem occurs when the Calendar element throws
java.lang.IllegalArgumentException: Cannot format given Object as a Date
If I submit the form and the forms finds errors during validation (related or unrelated to this Calendar field) there are no problems, only after validation is completed, and I add this message does it throw this exception.
Code for how I am generating the Calendar is below, but I am not sure why it would only throw an error in this scenario and not any other.
Calendar input = new Calendar();
input.setPattern("MM/dd/yyy");
input.setId(inputId);
input.setStyleClass(inputId);
input.setShowOn("button");
input.setNavigator(true);
input.setValueBinding("value", vb);
if(defaultVal != null && !defaultVal.equals("")){
SimpleDateFormat dbFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat displayFormat = new SimpleDateFormat("MM/dd/yyyy");
String defaultDate = displayFormat.format(dbFormat.parse(defaultVal));
Date date = new Date();
date = displayFormat.parse(defaultDate);
if(required != null && !required.equals("") && !required.equals(",") && mandatory.length > 1){
if(mandatory[1].equalsIgnoreCase("Y")){
input.setRequired(true);
input.setRequiredMessage("Please enter a "+inputLabel+".");
HtmlMessage message = new HtmlMessage();
message.setFor(inputId);
message.setStyleClass("errorMessage");
div.getChildren().add(input);
div.getChildren().add(message);
}else{
input.setRequired(false);
div.getChildren().add(input);
}
}else{
div.getChildren().add(input);
}
}
Related
I want to send this request
http://localhost:8080/{url}?start=2020-04-20&end=2020-04-24&status=success&status=failed
In Transaction model
private java.sql.Timestamp addedOn;
I am trying to create a dynamic query for multiple filters following this blog:
https://attacomsian.com/blog/spring-data-jpa-specifications
Specs.java file toPredicate method
if (criteria.getOperation().equals(SearchOperation.GREATER_THAN)) {
predicates.add(builder.greaterThan(
root.get(criteria.getKey()), criteria.getValue().toString()));
} else if (criteria.getOperation().equals(SearchOperation.LESS_THAN)) {
predicates.add(builder.lessThan(
root.get(criteria.getKey()), criteria.getValue().toString()));
}
Here is my Controller code
Timestamp start = new Timestamp(dateFormat.parse(request.getParameter("start")).getTime());
Timestamp end = new Timestamp(dateFormat.parse(request.getParameter("end")).getTime());
Specs txnSpecs = new Specs();
txnSpecs.add(new SearchCriteria("addedon", start, SearchOperation.GREATER_THAN_EQUAL));
txnSpecs.add(new SearchCriteria("addedon", end, SearchOperation.LESS_THAN_EQUAL));
txnSpecs.add(new SearchCriteria("status", Arrays.asList(request_params.get("status")), SearchOperation.IN));
List<Transaction> txnList = transactionRepository.findAll(txnSpecs);
return txnList;
But when I make request I get:
nested exception is java.lang.IllegalArgumentException: Parameter value [2020-04-20] did not match expected type [java.util.Date (n/a)]]
Do I need to convert the Date value before I send it as param for the SQL query? Or I need to use other types of Date?
Do I need to convert the Date value before I send it as param for the SQL query?
No, the opposite is true, you must keep it a Date but you convert it to a String by calling criteria.getValue().toString().
Check if your dateFormat are correct to pattern of your value: yyyy-MM-dd :
DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd");
I am trying to input some data into a mysql database. However, when I try to run the program I get this error:java.lang.IllegalArgumentException: An instance of a null PK has been incorrectly provided for this find opertaion, I suspect this is due to event.setPriority(prist); however I am not experienced enough to tell why and how I can fix it.
try{ Calendar duedate = Calendar.getInstance();
Listevent event = new Listevent();
TimeTableAddEvent tb = new TimeTableAddEvent();
int prist = Integer.parseInt(PriTxt.getText());
event.setName(EventTxt.getText());
event.setDescription(DescTxt.getText());
event.setPriority(prist);
event.setDateofdue(DateTxt.getDate());
EntityManagerFactory emf = Persistence.createEntityManagerFactory("TimeEven DataBasePU");
ListeventJpaController lejc = new ListeventJpaController((emf));
lejc.create(event);
}catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
#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.!