Skip to content

Instantly share code, notes, and snippets.

View itzg's full-sized avatar

Geoff Bourne itzg

View GitHub Profile
public class SomeManagedBean {
private ServiceA someService;
public int doSomething() {
... logic to be tested ...
someService.doSomethingElse();
}
public void setSomeService(ServiceA someService) {
this.someService = someService;
public class VagueGroovyInGrails {
// Typical service injection by Grails
// It's type is...? It's resolved dynamically at runtime
def someService
void doSomething() {
// Call a service method. Does that method exist?
// Who knows? We don't even know what class type it is at compile time.
someService.doYourThing();
}
@itzg
itzg / content.md
Created October 11, 2012 04:48
Using messages in Spring MVC

First declare a messageSource bean and using that specific id is important.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
@itzg
itzg / gist:3881194
Created October 12, 2012 20:01
Resolving download error of maven-cli-plugin-parent while running atlas-* commands

While running

atlas-run-standalone --product jira

at work where OpenDNS is being used, I was getting this maven download error

[INFO] Scanning for projects...
@itzg
itzg / log4j.xml
Created October 17, 2012 20:51
Good starter log4j.xml file for use with Spring apps
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c - %m%n" />
</layout>
</appender>
@itzg
itzg / gist:3928120
Created October 21, 2012 19:09
toString template to use in Eclipse
@Override
public String toString() {
StringBuilder sb = new StringBuilder(${enclosing_type}.class.getSimpleName());
sb.append(":[");
sb.append("${field}=").append(${field});
sb.append(",").append(",super=").append(super.toString()).append("]");
return sb.toString();
}
@itzg
itzg / web.xml
Created October 23, 2012 20:45
Typical web.xml for Spring MVC running on Servlet 2.5
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
</context-param>
@itzg
itzg / gist:3956710
Created October 26, 2012 03:31
Open jQuery UI menu on button click
// Create and hide the menu initially
var menu = $("ul#menu").menu().hide();
$("#openMenuBtn).button()
.click(function() {
// Make use of the general purpose show and position operations
// open and place the menu where we want.
menu.show().position({
my: "left top",
at: "left bottom",
@itzg
itzg / gist:3966546
Created October 27, 2012 22:01
html,body styling for full window web apps
html, body {
height: 100%;
min-height: 100%;
overflow: hidden;
margin: 0;
padding: 0;
font-size: 12pt;
font-family: sans-serif;
}
@itzg
itzg / gist:3967247
Created October 28, 2012 02:43
In JS constructor accept an optional 'options' object
var layout = {
Box: function(container, options) {
$.extend(this, {
vertical: false
}, options);
};
// HOWEVER, for Eclipse to discover the fields of Box, this approach is
// needed