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.!
Related
I have been looking and trying solutions provided on the web (and SO) for the last hour on how to use the Date type in Java but I can't seem to get it working. I am using NetBeans 11.2 and I am not used to Java and it is giving me a hard time (no pun intended). It seems that LocalDateTime, Date and Time are deprecated and that I should be using java.time.
To be honest, I don't know what to do anymore. I am trying to build a query with inputs value to save in mySQL database.
The source of the Date is from <input type="date">
SignIn.java (servlet) :
String birthDate = request.getParameter("data_birthdate");
UserDto userDto = null;
UserDao userDao = new UserDao();
try
{
// Tried this
userDto = userDao.CreateUser(LocalDateTime.parse(birthDate));
// Tried that
userDto = userDao.CreateUser(Date.parse(birthDate));
// Tried this
userDto = userDao.CreateUser(Time.parse(birthDate));
}
userDao.java (Dao) :
public void CreateUser(Date dateBirth) throws SQLException {
try {
connect = db.getConnect();
ps = connect.prepareStatement(SQL_CreateUser);
ps.setDate(1, dateBirth);
ps.executeUpdate();
}
}
You may use LocalDateTime along with PreparedStatement#setTimestamp(). Here is roughly how you would do that:
String birthDate = request.getParameter("data_birthdate");
// assuming your text birthdates look like 1980-12-30 00:30:05
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dt = LocalDateTime.parse(birthDate, formatter);
try {
connect = db.getConnect();
ps = connect.prepareStatement(SQL_CreateUser);
ps.setTimestamp(3, Timestamp.valueOf(dt));
}
catch (Exception e) {
// handle exception
}
Note carefully the format mask being used in the call to DateTimeFormatter#ofPattern. You need to replace that with whatever mask actually fits your string dates.
#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 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);
}
}
I am having a problem handling date variables when I write to PostgreSQL using JSP forms. There has been some great tips but still can not get it right. I believe that I am passing a String from JSP to JAVA where it is a Date "setter" and "getter" writing to PSQL on a "date without time zone" column.
Here is parts of the JSP code related to the Date:
.... (some code) ....
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
.... (mode code) ....
<%
if (action.equals("add")) {
.
.
.
newCampaign.setCampempDate(dateFormat.parse(request.getParameter("campemp")));
newCampaign.add();
}
%>
.... (more code) ....
<input name="campemp" type="text" class="datePickBox" id="campemp"
onBlur="javascript:checkFormat(this)" value="<%= defaultCampaign.getCampempDate() != null
? dateFormat.format(defaultCampaign.getCampempDate()) : dateFormat.format(new
java.util.Date()) %>" size=20>
.... (rest of code) ....
It is important to mention that on the input I am also using a calendar that passes the date with the correct format... this is another reason I am using a date field on the JSP side.
On the JAVA side:
.... (some code) ....
private java.util.Date campemp= null;
private SimpleDateFormat userDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
... (more code) ... ++ Set and Get ++
public void setCampempDate(java.util.Date aCampemp) {
this.campemp= aCampemp;
}
public java.util.Date getCampempDate() {
return this.campemp;
}
... (more code) ... ++ LOAD ++
public void load(ResultSet rs) throws SQLException {
this.setId(rs.getLong("campkeydbid"));
.
.
this.setCampempDate(rs.getDate("campemp"));
}
... (more code) ... ++ WRITE TO DB ++
public boolean add() throws SQLException {
boolean success = false;
if (costingEnabled) {
String call = "select " + getStoredProcedureMapper().getPrefix() + "_Add(?,?,?,?,?,?,?,?,?,?)";
DataSource ds = PoolMan.findDataSource("mydatabase");
Connection conn = null;
try {
conn = ds.getConnection();
PreparedStatement pst = conn.prepareStatement(call);
.
.
pst.setTimestamp(10, new Timestamp(this.getCampempDate().getTime()));
ResultSet rs = pst.executeQuery();
if (rs.next()) {
.
.
... (more code) ...
The "_Add" on the stored procedure is correct as it works if I "hardcode" the date on the pst.SetTimestamp
The error I am getting is the following:
org.apache.jasper.JasperException: Unable to convert string "04/07/2012 19:12" to class "java.util.Date" for attribute "campemp": Property Editor not registered with the PropertyEditorManager
Any ideas on a workaround to parse the String to Date without affecting the DB date field and JSP input will be greatly appreciated.. thank you very much.
Regards,
Rob
org.apache.jasper.JasperException: Unable to convert string "04/07/2012 19:12" to class "java.util.Date" for attribute "campemp": Property Editor not registered with the PropertyEditorManager
You are passing Date in String in 04/07/2012 19:12 format so you need to use
dd/MM/yyyy HH:mm
From the code you posted, It seems you are using
private SimpleDateFormat userDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
as format in SimpleDateFormat
I'm using Bloomberg Java api to download trading data. I need somebody to tell me if there exists a function which can return a list of trading holidays. I looked through the manual but couldn't find one. If there's no such a thing, is there a good way that I can create one? Thanks.
String field = "CALENDAR_HOLIDAYS";
//String field = "CALENDAR_NON_SETTLEMENT_DATES";
Request request = this._refDataServiceM.CreateRequest("ReferenceDataRequest");
Element securities = request.GetElement("securities");
securities.AppendValue("AAPL US Equity");
Element fields = request.GetElement("fields");
fields.AppendValue(field);
Element overridefields = request.GetElement("overrides");
Element overrides = request.GetElement("overrides");
Element override1 = overrides.AppendElement();
override1.SetElement("fieldId", "SETTLEMENT_CALENDAR_CODE");
override1.SetElement("value", calendar_code);
Element override2 = overrides.AppendElement();
override2.SetElement("fieldId", "CALENDAR_START_DATE");
override2.SetElement("value", startDate.ToString("yyyyMMdd"));
Element override3 = overrides.AppendElement();
override3.SetElement("fieldId", "CALENDAR_END_DATE");
override3.SetElement("value", endDate.ToString("yyyyMMdd"));
The Bloomberg API will tell you, for a given security, the appropriate calendar code using DS853 (CALENDAR_CODE). Given a calendar code, I do not believe that Bloomberg provides a way to download a holiday calendar. You may need to use a third party vendor such as Financial Calendar.
I had issues getting the accepted answer to work. Turned out the SETTLEMENT_CALENDAR_CODE isn't needed. The following worked:
{
securities[] = {
/bbgid/BBG00HZZLBT7
}
fields[] = {
CALENDAR_NON_SETTLEMENT_DATES
}
overrides[] = {
overrides = {
fieldId = "CALENDAR_START_DATE"
value = "20180101"
}
overrides = {
fieldId = "CALENDAR_END_DATE"
value = "20190101"
}
}
tableOverrides[] = {
}
}
Response:
{
securityData[] = {
securityData = {
security = "UXA INDEX"
eidData[] = {
}
fieldExceptions[] = {
}
sequenceNumber = 0
fieldData = {
CALENDAR_NON_SETTLEMENT_DATES[] = {
CALENDAR_NON_SETTLEMENT_DATES = {
Holiday Date = ...
}
CALENDAR_NON_SETTLEMENT_DATES = {
Holiday Date = ...
}
...
}
}
}
}
}
The Bloomberg holiday data is lacking sometimes. You could try a service that specializes in trading holidays data like TradingHours.com.
https://www.tradinghours.com/docs/3.x/enterprise/market-holidays.html
The Python implementation is as follows. Note that we are using calendar "AM" for Amsterdam, marking the second day of easter as a national holiday.
refDataService = session.getService("//blp/refdata")
request = refDataService.createRequest("ReferenceDataRequest")
request.append("securities", "AAPL US Equity")
request.append("fields", "CALENDAR_HOLIDAYS")
overrides = request.getElement("overrides")
override2 = overrides.appendElement()
override2.setElement("fieldId", "CALENDAR_START_DATE")
override2.setElement("value", "20200101")
override3 = overrides.appendElement()
override3.setElement("fieldId", "CALENDAR_END_DATE")
override3.setElement("value", "20210501")
override4 = overrides.appendElement()
override4.setElement("fieldId", "SETTLEMENT_CALENDAR_CODE")
override4.setElement("value", "AM")
session.sendRequest(request)