Giter VIP home page Giter VIP logo

vraptor-freemarker's Introduction

vraptor-freemarker

Build status

A simple freemarker engine for rendering templates from within jar files, or rendering email etc.

installing

Vraptor-freemarker.jar can be downloaded from maven's repository, or configured in any compatible tool:

	<dependency>
		<groupId>br.com.caelum.vraptor</groupId>
		<artifactId>vraptor-freemarker</artifactId>
		<version>1.1.0</version>
		<scope>compile</scope>
	</dependency>

usage for rendering pages

	@Resource
	public class DashboardController {

		private final User user;
		private final Freemarker freemarker;

		public DashboardController(User user, Freemarker freemarker) {
			this.user = user;
			this.freemarker = freemarker;
		}

		@Path("/admin/dashboard")
		@Get
		public void list() throws IOException, TemplateException {
			freemarker.use("dashboard").with("currentUser", user).render();
		}

	}

or...

	@Resource
	public class DashboardController {

		private final User user;
		private final Result result;

		public DashboardController(User user, Result result) {
			this.user = user;
			this.result = result;
		}

		@Path("/admin/dashboard")
		@Get
		public void list() throws IOException, TemplateException {
			result.include("currentUser", user);
			result.use(FreemarkerView.class).withTemplate("dashboard");
		}

	}

usage for rendering emails

	String body = freemarker.use("send_mail_notification").with("currentUser", user).getContent();

usage when testing

	@Test
	public void testSomething() throws Exception {
		new DashboardController(new User(), new MockFreemarker()).list();
		// your assertions here
	}

help

Get help from vraptor developers and the community at vraptor mailing list.

vraptor-freemarker's People

Contributors

luiz avatar toshikurauchi avatar leocwolter avatar

Stargazers

David Araújo avatar Narciso avatar

Watchers

Alberto Luiz Souza avatar Adriano Almeida avatar  avatar Lucas Cavalcanti avatar Ceci Fernandes avatar Paulo Silveira avatar Guilherme Moreira avatar Nico Steppat avatar Diego Maia (Bronx) avatar  avatar Tiago Oliveira avatar Erich avatar James Cloos avatar Chico Sokol avatar  avatar  avatar Rodrigo Turini avatar Art Diniz Adam avatar Joviane Fernandes Jardim avatar  avatar  avatar

vraptor-freemarker's Issues

Make it easier to be tested

Implement MockTemplate and MockFreemarker so that one doesn't need to mock the calls to Freemarker.use and Template.with

Use Result instead of specific class

Currently, to use Freemarker as the template engine, one must require the Freemarker class in the constructor and use its methods to include variables in the scope of the template.

It would be better if one could use the VRaptor's Result instead, keeping the standard of the framework and easing a possible template engine change. The final result could be something like this:

result.include("anObject", anObject);
result.use(Freemarker.class).of("path/to/template")

Example

Hi, can you create some example because i have exception when added
result.include("dao",dao.listAll());
result.use(FreemarkerView.class).withTemplate("list");
I didn't use maven. Thank you in advance!

org.jboss.weld.exceptions.IllegalArgumentException: WELD-001456 Argument bean must not be null
at org.jboss.weld.util.Preconditions.checkArgumentNotNull(Preconditions.java:40)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:732)
at org.jboss.weld.util.ForwardingBeanManager.getReference(ForwardingBeanManager.java:61)
at org.jboss.weld.bean.builtin.BeanManagerProxy.getReference(BeanManagerProxy.java:69)
at br.com.caelum.vraptor.ioc.cdi.CDIBasedContainer.instanceFor(CDIBasedContainer.java:59)
at br.com.caelum.vraptor.ioc.cdi.CDIBasedContainer$Proxy$_$$WeldClientProxy.instanceFor(Unknown Source)
at br.com.caelum.vraptor.core.DefaultResult.use(DefaultResult.java:82)
at br.com.caelum.vraptor.core.DefaultResult$Proxy$
$$WeldClientProxy.use(Unknown Source)
at com.tlogica.cyrillicexperiment.controller.PersonsController.list(PersonsController.java:36)
at com.tlogica.cyrillicexperiment.controller.PersonsController$Proxy$
$$WeldClientProxy.list(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:38)
at net.vidageek.mirror.invoke.MethodHandlerByMethod.withArgs(MethodHandlerByMethod.java:54)
at br.com.caelum.vraptor.core.DefaultReflectionProvider.invoke(DefaultReflectionProvider.java:42)
at br.com.caelum.vraptor.core.DefaultReflectionProvider$Proxy$
$$WeldClientProxy.invoke(Unknown Source)
at br.com.caelum.vraptor.observer.ExecuteMethod$1.call(ExecuteMethod.java:82)
at br.com.caelum.vraptor.observer.ExecuteMethod$1.call(ExecuteMethod.java:72)
at br.com.caelum.vraptor.core.Try.run(Try.java:18)
at br.com.caelum.vraptor.observer.ExecuteMethod.execute(ExecuteMethod.java:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:93)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:274)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:261)
at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:240)
at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:170)
at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:166)
at org.jboss.weld.event.TransactionalObserverNotifier.notifyObserver(TransactionalObserverNotifier.java:44)
at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:120)
at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:113)
at org.jboss.weld.event.EventImpl.fire(EventImpl.java:79)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:78)
at br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:75)
at br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor$Proxy$
$$WeldClientProxy.intercept(Unknown Source)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler$1.call(ToInstantiateInterceptorHandler.java:71)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler$1.call(ToInstantiateInterceptorHandler.java:68)
at br.com.caelum.vraptor.core.Try.run(Try.java:18)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.executeSafely(ToInstantiateInterceptorHandler.java:68)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:61)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:83)
at br.com.caelum.vraptor.interceptor.FlashInterceptor.intercept(FlashInterceptor.java:98)
at br.com.caelum.vraptor.interceptor.FlashInterceptor$Proxy$
$$WeldClientProxy.intercept(Unknown Source)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler$1.call(ToInstantiateInterceptorHandler.java:71)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler$1.call(ToInstantiateInterceptorHandler.java:68)
at br.com.caelum.vraptor.core.Try.run(Try.java:18)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.executeSafely(ToInstantiateInterceptorHandler.java:68)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:61)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:83)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.start(DefaultInterceptorStack.java:93)
at br.com.caelum.vraptor.core.DefaultInterceptorStack$Proxy$
$$_WeldClientProxy.start(Unknown Source)
at br.com.caelum.vraptor.observer.RequestHandlerObserver.handle(RequestHandlerObserver.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:93)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:274)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:261)
at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:240)
at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:170)
at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:166)
at org.jboss.weld.event.TransactionalObserverNotifier.notifyObserver(TransactionalObserverNotifier.java:44)
at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:120)
at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:113)
at org.jboss.weld.event.EventImpl.fire(EventImpl.java:79)
at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:123)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.