Friday, September 19, 2014

How to get hour value in 24 hour format

Calendar calendar = Calendar.getInstance();
System.out.println(calendar.get(Calendar.HOUR_OF_DAY)); // print hour in 24 format

Thursday, September 18, 2014

Java Calendar - Calendar.MONTH is zero-based

Calendar calendar = Calendar.getInstance();
calendar.set(2010, 4, 10);
System.out.println(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));

It's weird thing calendar.set(2010, 4, 10), actually set date as May 10, 2010. "4" for the MONTH field is really misleading. It sets Month as "May".

caalendar.getActualMaximum() calculates the maximum of days in month of May.

So output should be:
31
10

Wednesday, July 30, 2014

ADF and Time zone


I will implement this and come back to this later.

Time zone
http://adfnbpel.wordpress.com/2013/03/20/to-set-user-timezone-for-adf-datetime-fields/

Tuesday, July 29, 2014

How Language ISO and Locale ID works


"A language ID designates a written language (or orthography) and can reflect either the generic language or a specific dialect of that language. To specify a language ID, you use a language designator by itself. To specify a specific dialect of a language, you use a hyphen to combine a language designator with a region designator. Thus, the English language as it is spoken in Great Britain would yield a language ID of en-GB, while the English language spoken in the United States would have a language ID of en-US. To specify the generic version of the English language, you would use the language ID en by itself."


"A locale ID identifies a specific location where a given language is spoken. To specify a locale ID, use an underscore character to combine a language designator with a region designator. The locale ID for English-language speakers in Great Britain is en_GB, while the locale for English-speaking residents of the United States is en_US. Although locale IDs and language IDs might seem nearly identical, there is a subtle difference. A language ID identifies a written and spoken language only. A locale identifies a region and its conventions and has a more cultural context."


"To illustrate the difference between language IDs and locale IDs, consider the following example. The dialect for a resident of Great Britain is specified by the code en-GB. The commonly used locale for that same person is en_GB. If you wanted to be very precise when specifying the locale, you could specify the locale code as en-GB_GB. This specifies a person who speaks the British dialect of English and who resides in Great Britain. If that same person moved to the United States, the appropriate locale would been-GB_US, which would identify a person who speaks British English but uses the regional settings associated with the United States."

See https://developer.apple.com/library/mac/documentation/macosx/conceptual/bpinternational/Articles/LanguageDesignations.html
http://www.oracle.com/technetwork/java/javase/javase7locales-334809.html

Tuesday, July 22, 2014

How to display date and time in ADF UI

In ADF, in order to display date + time in ADF UI, use <af:convertdatetime>:
<af:column filterable="true" headertext="#{bindings.View1.hints.DisplayDateTime.label}" id="c19" sortable="true" sortproperty="DisplayDateTime" width="150">
<f:facet name="filter">
<af:inputdate id="id6" value="#{vs.filterCriteria.DisplayDateTime}">
</af:inputdate></f:facet>
<af:outputtext id="ot33" value="#{row.DisplayDateTime}">
<af:convertdatetime datestyle="medium" locale="#{sessionScope.UserLocale}" pattern="#{bindings.View1.hints.DisplayDateTime.format}" timestyle="short" type="both"></af:convertdatetime></af:outputtext>
</af:column>

Monday, July 7, 2014

SQL error ORA-01722: invalid number tips

Usually this is because INSERT or UPDATE and the conversion from chars to number failed.

But when this is happened in SELECT statement:

It's probably because the implicit conversion in WHERE clause.

SELECT * 
FROM ( SELECT FLAG, TO_NUMBER ( NUM ) NUM 
FROM SUBTEST 
WHERE FLAG = 'N' ) 
WHERE NUM > 0 ;

See here

Tuesday, May 27, 2014

ADF SelectOneChoice Required Validation

<af:selectOneRadio value="" id="sor1" required="true" autoSubmit="true" label="text">                          <f:selectItems value=""" id="si2"/>
</af:selectOneRadio>

  • SelectOneChoice with no selection option as first item. It returns "" instead of NULL so required doesn't fire.
    • one solution is to remove the no selection option.

Wednesday, May 14, 2014

Java Date Format and Current Date Time

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date));
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
System.out.println(dateFormat.format(cal.getTime()));

Monday, April 28, 2014

Apply patch 18277370 to JDeveloper 11.1.1.7.0


Why?


Oracle has fixes for ADF application running in Internet Explorer 11 (IE 11).

Without patch, ADF application can only run in compatibility mode in IE 11. You see a message box below:

How?


You need:
  • Download patch zip file from Oracle Support
  • Unzip it to a folder like C:\temp folder as example
  • Have Java JDK installed, e.g. C:\Java\jdk1.7.0_51

Apply the patch:

Open Command prompt and do it in two steps:
  • Step I
    • cd C:\temp\p18277370_111170_Generic\18277370\oui\18277370
    • set ORACLE_HOME=C:\oracle\Middleware\oracle_common
    • C:\oracle\Middleware\oracle_common\OPatch\opatch apply -jdk C:\Java\jdk1.7.0_51
  • Step II
    • cd C:\temp\p18277370_111170_Generic\18277370\sa\18277370
    • set ORACLE_HOME=C:\oracle\Middleware\jdeveloper
    • C:\oracle\Middleware\oracle_common\OPatch\opatch apply -jdk C:\Java\jdk1.7.0_51
Important: remove weblogic server cache and IE 11 cache.


After apply patch, running ADF applcation, no more ugly unsupported message box!

Monday, April 14, 2014

jsFiddle a good tool for HTML, css, and javascript

jsFiddle is a convenient tool to quickly test your JavaScript, HTML, and CSS code right inside your browser.

Go to jsFiddle and give it a try.

Friday, January 3, 2014

ADF selectBooleanCheckbox lost values

This is JDeveloper 11.1.1.6. In order to test it, I created a table in HR schema.

CREATE TABLE "DEPT_WITH_FLAG"
( "DEPTNO" NUMBER(2,0) PRIMARY KEY,
"DNAME" VARCHAR2(14),
"LOC" VARCHAR2(13),
"FLAG" CHAR(1)
) ;


Oracle ADF faces component selectBooleanCheckbox has an issue.

It can be reproduced with a very simple application created:
- create an entity object with database table
(one of the table columns has only Y/N values, which is the recommended way of boolean type column)
- create a view object based on this entity object
- create a page and drag the VO created to page as a table
- create a button binding and assoociate it to the boolean cloumn
- create a button to show / hide the table

When using selectBooleanCheckbox as column in a table, After hide -> show the table, all checked checkbox lost their value (unchecked). You can download the test source here: Checkbox.zip

Oracle forum for this issue:
https://community.oracle.com/thread/2594029