Wednesday

Postgres >> manually alter sequence next value

SELECT setval('my_seq', 100, FALSE);
--my_seq >> your sequence name
-- 100 >> value you want to set
-- false >> means the next value would be 100
--       >> if it would be true then next value will be 100+1 = 101

Monday

How to access JBoss over an another host

For accessing JBOSS or Wildfly from another host outside of localhost:

<!-- in standalone.xml  there is a definition as follows-->
<interface name="public">
    <inet-address value="${jboss.bind.address:127.0.0.1}"/>
</interface>

<!--you can do any of the following -->

<!-- 1. choice: 
     binding for all the IP Addresses 
-->
<interface name="public">
     <inet-address value="${jboss.bind.address:0.0.0.0}"/>
</interface>

<!-- 2. choice: 
     binding for only one IP adress 
-->
<interface name="public">
     <inet-address value="${jboss.bind.address:192.168.x.x}"/>
</interface>

<!-- 3. choice:
     double click on server 
     then click 'Open launch configuration'
     then add -b 0.0.0.0 to the  'Arguments' 'Program arguments' 
-->

Friday

How to check for the existence of undeclared variable in js

You can check for the existence of undeclared variable in javascript without getting ReferenceError:
if (x !== undefined){} // gets error if x undeclared
if (x !== 'undefined'){} // gets error if x undeclared
if (typeof x !== undefined){} // gets error because typeof x returns "undefined"

if (typeof x !== 'undefined'){} //right one

Tuesday

How to learn which vendor / version is using in jsf webapp? (MyFaces or Mojarra)

You can run the following code fragment in your application:
import javax.faces.context.FacesContext;

System.out.println("imp title: " + FacesContext.class.getPackage().getImplementationTitle());
System.out.println("impl vendor " + FacesContext.class.getPackage().getImplementationVendor());
System.out.println("imp version: " + FacesContext.class.getPackage().getImplementationVersion());
Sample output:

imp title: Apache MyFaces JSF-2.2 Core API
impl vendor The Apache Software Foundation
imp version: 2.2.11

Dynamically calling a class - method in java by using reflection

Dynamically call a method on a dynamically given class by using reflection:
import java.lang.reflect.Method;

try {
       String myClassName = "tr.com.xx.xx.xx.Example";
       String myMethodName = "exampleMethod";

       Class<?> myClassRef = Class.forName(myClassName);
       Object instanceOfMyClass = myClassRef.newInstance();
       
       //my object input types in order: param1(int), param2(String), param3(MyDTO), param4(List<MyDTO>)
       Method method = myClassRef.getDeclaredMethod(myMethodName, int.class, String.class, MyDTO.class, List.class);
       MyResult respoonse = (MyResult) method.invoke(instanceOfMyClass, param1, param2, param3, param4);
       System.out.println("response" + response.getX());

} catch(Exception e) {
       //logging
       System.out.println(e.getMessage());

Hint: shaking problems in Safari

Container has been shaking chidren on safari. However in chrome, ie, firefox it works well.

Advice:
Dynamically height calculation shakes children on safari.
Check for any dynamically calculation for height. Then try to give "position: fixed" or try to avoid giving height dynamically.

JSTL format number

Add following taglib to your class:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<fmt:formatNumber value="${your double value}" maxFractionDigits="0"  groupingUsed="false" />
<!-- your value example :1500.0 then it will show 1500 ! -->
<!-- You can use it instead of <c:out /> which doesn’t have so much control for formatting -->

Why is SimpleDateFormat changing given date?

//The upper case Y is "week year". It has 364 or 371 days 
//The lower case y has usual 365 or 366.
//So they give different outputs:
//Locale.forLanguageTag("tr_TR") >> comes with Java 7

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;


public class Test {

    public static void main(String[] args) {
       try {
           String dateString = new java.util.Date().toString();
           System.out.println(dateString);

           SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.forLanguageTag("tr_TR"));
           Date date = format.parse(dateString);
           System.out.println(date.toString());

           SimpleDateFormat format2 = new SimpleDateFormat("EEE MMM dd HH:mm:ss z YYYY", Locale.forLanguageTag("tr_TR"));
           Date date2 = format2.parse(dateString);
           System.out.println(date2.toString());

       } catch (ParseException e) {
           //log
       }
    }
    
}
Output:

Mon May 14 10:31:14 EEST 2018
Mon May 14 10:31:14 EEST 2018
Mon Jan 01 09:31:14 EET 2018

Friday

f:selectItems => adding tooltip

Put pass-through into to the namespace.
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"

You can use passthrough 'title' attribute:
<f:selectItems value="#{values}" pt:title="Your tooltip desc"/>

Execute two methods in action

You can use f:actionListener to execute 2 methods in action:
<a4j:commandbutton action="{method1()}" value="deneme" >                              
   <f:actionlistener binding="#{method2()}"/>
<a4j:commandbutton>