Forked from guilhermesilveira/ApplicationHelper.java
Last active
December 23, 2015 06:59
-
-
Save rponte/6598027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class ApplicationHelper implements ViewHelper { | |
private final PrettyTimeFormatter formatter; | |
public ApplicationHelper(PrettyTimeFormatter formatter) { | |
this.formatter = formatter; | |
} | |
public String format(AbstractInstant instant) { | |
return formatter.format(instant); | |
} | |
@Override | |
public String getName() { | |
return "app"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Intercepts(before=ForwardToDefaultViewInterceptor.class) | |
class HelpersInterceptor implements Interceptor{ | |
private final List<ViewHelper> helpers; | |
private final Result result; | |
public HelpersInterceptor(List<ViewHelper> helpers, Result result) { | |
this.helpers = helpers; | |
this.result = result; | |
} | |
@Override | |
public boolean accepts(ResourceMethod method) { | |
return true; | |
} | |
@Override | |
public void intercept(InterceptorStack stack, ResourceMethod method, | |
Object args) throws InterceptionException { | |
for (ViewHelper helper : helpers) { | |
// result.include(helper.getClass().getSimpleName(), helper); | |
result.include(helper.getName(), helper); // <3 | |
} | |
stack.next(method, args); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> | |
<%@attribute name="time" required="true" type="org.joda.time.base.AbstractInstant"%> | |
<% | |
if (time != null) { | |
org.joda.time.base.AbstractInstant time = (org.joda.time.base.AbstractInstant) jspContext.getAttribute("time"); | |
br.com.caelum.gnarus.utilMovePlease.PrettyTimeFormatter formatter = (br.com.caelum.gnarus.utilMovePlease.PrettyTimeFormatter) request.getAttribute("timeFormatter"); | |
out.write(formatter.format(time)); | |
} | |
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
${app.format(usuario.createdAt)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ViewHelper { | |
public String getName(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment