Tag Archives: Java

Swing Textfield selectAll without invokeLater

Get rid of the evil invokeLater. InvokeLater will pollute the UX design. private class SelectAllOfFocus extends FocusAdapter { @Override public void focusGained(FocusEvent e) { if (! e.isTemporary()) { JFormattedTextField textField = (JFormattedTextField)e.getComponent(); // This is needed to put the text field in edited mode, so that its processFocusEvent doesn’t // do anything. Otherwise, it calls… Read More »

Reference java env variable in spring config

How to reference java environment variable when using spring config For example: Using Tomcat server, ${catalina.home} is one of the system variable provided by Tomcat In abc.properties file, test.ref1=${catalina.home} In context.xml (or whatever context xml file you referencing), <!– Properties –> <bean class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>    <property name=”locations”>    <list>       <value>classpath:properties/abc.properties</value>    </list>  … Read More »

Xfire unable to comm. to server under proxy

Log shows xfire.transport.http.HttpChannel Server returned error code = 417 It sounds like xfire added a “Expect 100 continue” in the header once an outgoing proxy is used. (E.g. by java property, -Dhttp.proxyHost=10.1.1.1 -Dhttp.proxyPort=8080) If a reverse proxy server is used, the reverse proxy server may not response to Expect header. Two solutions: For apache as… Read More »

Java report system

Opensource Candidate: Jasper Report (http://community.jaspersoft.com/project/jasperreports-library/resources) Dynamic Report (http://www.dynamicreports.org/) Dynamic Jasper (http://dynamicjasper.com/) Comparison Part 1 http://lagivan.blogspot.hk/2011/10/choosing-java-reporting-tool.html Comparison Part 2 http://lagivan.blogspot.hk/2011/11/choosing-java-reporting-tool-part-2.html

Customize order by in JPQL

Ref : http://stackoverflow.com/questions/9262413/hibernate-dynamic-order For example, if there is a customize ordering in enum or a specific field. We can use “Case when ? else ? end” syntax in order by. (Supported in JPA) SELECT o FROM Cat o ORDER BY CASE o.name WHEN ‘Tom’ THEN 0 ELSE 1 END

JavaMailSenderImpl sample

– By pass cert installation – Require logon – Dump debug message   <bean id=”javaMail” class=”org.springframework.mail.javamail.JavaMailSenderImpl”> <property name=”host” value=”${mail.host}”/> <property name=”port” value=”${mail.port}”/> <property name=”username” value=”${mail.username}”/> <property name=”password” value=”${mail.password}”/> <property name=”javaMailProperties”> <props> <prop key=”mail.smtp.auth”>true</prop> <prop key=”mail.smtp.starttls.enable”>true</prop> <prop key=”mail.smtp.ssl.trust”>*</prop> <prop key=”mail.debug”>true</prop> </props> </property> </bean>

What is @Repository advantage

The @Repository annotation is yet another stereotype that was introduced in Spring 2.0. This annotation is used to indicate that a class functions as a repository and needs to have exception translation applied transparently on it. The benefit of exception translation is that the service layer only has to deal with exceptions from Spring’s DataAccessException… Read More »

Java log viewer

log4j Chainsaw logger viewer – (http://logging.apache.org/chainsaw/index.html) Otros log viewr – (http://code.google.com/p/otroslogviewer/) logback logger Lilith logger viewer – using socket/native appender to communicate (http://lilith.huxhorn.de/)