Skip to content

Instantly share code, notes, and snippets.

View prule's full-sized avatar

Paul Rule prule

View GitHub Profile
@prule
prule / gist:5572715
Created May 14, 2013 00:36
Sometimes its useful to expose the version of your web application - I find it useful so vsConsole can display the version of the deployed application for each environment on the dashboard. If you build your app with Maven, you can use this code to get the version, and simply wire up a controller/rest endpoint to return it as text/plain.
private static final String VERSION_KEY = "version";
private static final String POM_PROPS_PATH_MF = "/META-INF/maven/{0}/{1}/pom.properties";
public static String getMavenWarVersion(ServletContext context, String groupId, String artifactId) {
String resourceName = MessageFormat.format(POM_PROPS_PATH_MF, new Object[]{groupId, artifactId});
Properties properties = loadProperties(context.getResourceAsStream(resourceName));
if (properties != null) {
return properties.getProperty(VERSION_KEY);
}
return "unknown";
@prule
prule / gist:5648809
Created May 25, 2013 11:42
A REST controller which can be used to expose the version of a WAR application built with Maven. Useful when used with vsConsole to monitor the versions of you applications deployed to various environments. See http://vs-console.appspot.com/
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.servlet.ServletContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import java.io.IOException;
@prule
prule / gist:5648830
Created May 25, 2013 11:49
Maven dependencies for adding Jersey support to your spring based web application.
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>1.8</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
@prule
prule / DateMidnightConverter
Created May 31, 2013 04:23
JSF converter for joda-time DateMidnight
import org.apache.commons.lang.StringUtils;
import org.joda.time.DateMidnight;
import org.joda.time.format.DateTimeFormat;
import org.springframework.stereotype.Component;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
@Component
@prule
prule / gist:5682948
Created May 31, 2013 04:31
Using the JSF DateMidnightConverter with Primefaces Calendar component
<p:row>
<p:column>
<p:outputLabel value="Date"/>
</p:column>
<p:column>
<p:calendar pattern="dd/MMM/yyyy" navigator="true" showButtonPanel="true"
converter="#{dateMidnightConverter}"
value="#{myBean.selected.date}"/>
</p:column>
</p:row>
@prule
prule / Abstract page object for selenium webdriver
Created August 17, 2013 08:29
My version of an Abstract Page Object for using with Selenium and JBehave - utility behaviour for clicking links by text, selecting a JSF/PrimeFaces selectOne option, and waiting for ajax to complete.
import net.thucydides.core.pages.PageObject;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public abstract class AbstractPage extends PageObject {
public AbstractPage(WebDriver driver) {
super(driver);
}
@prule
prule / Facelets (Primefaces) selectOneMenu
Created August 17, 2013 08:48
Sample Facelets code rendering a PrimeFaces selectOneMenu component
<p:selectOneMenu id="state" value="#{myBean.state}">
<f:selectItem itemLabel="- Select One -" itemValue=""/>
<f:selectItems value="#{optionsBean.states}" var="item"
itemLabel="#{item.name}"
itemValue="#{item}"/>
</p:selectOneMenu>
@prule
prule / selectOneMany HTML
Created August 17, 2013 08:50
HTML generated by PrimeFaces selectOneMany
<div id="myForm:state" class="ui-selectonemenu ui-widget ui-state-default ui-corner-all ui-helper-clearfix" style="width: 147px;">
<div class="ui-helper-hidden">
<select id="myForm:state_input" name="myForm:state_input">
<option value="">- Select One -</option>
<option value="Enabled">Enabled</option>
<option value="Disabled">Disabled</option>
</select>
</div>
<div class="ui-helper-hidden-accessible">
<input id="myForm:state_focus" name="myForm:state_focus" type="text">
@prule
prule / gist:6255979
Last active December 21, 2015 05:19
/*
The facelets code uses the id "state"
<p:selectOneMenu id="state" value="#{myBean.state}">
...
</p:selectOneMenu>
*/
// sample invocation to select element
@prule
prule / gist:6545157
Created September 12, 2013 23:25
Accessing the PrimeFaces artifacts via maven.
In section 2 of the documentation (http://www.primefaces.org/documentation.html), it shows how you can define the primefaces repository in your maven pom.xml (or ~/.m2/settings.xml):
<repository>
<id>prime-repo</id>
<name>Prime Repo</name>
<url>http://repository.primefaces.org</url>
</repository>
If you are using maven in an organisation you would be better off setting up a repository manager such as NEXUS and configuring that with the primefaces repository. Then, your developers just configure this nexus repository as a mirror of everything in their ~/.m2/settings.xml and everything is transparent.