This is a known problem (at least to me). Check https://java.net/jira/plugins/servlet/mobile#issue/ADFEMG-264 which describes a similar problem but you can see that the samples have the same problem. In jdev 12c Oracle changed how sessions are handled. To my knowledge there is no way to make the code you use work.
You need to file a SR with support.oracle.com and ask them to look into this.
There is an enhancement request ongoing (to my knowledge it's not visible) which should make it possible to detect session expiry and to redirect to a user defined page or do whatever the development wants.