updated for version 2.5.0

since version 2.2.0

Spring support for action pojos#

To configure action pojos with spring add the @Component spring annotation to the action pojo.

The scope should be @Scope("prototype") as the action will be created only once, but you could also use @Scope("request").

ztemplates will detect that and will use spring to create the pojo instance, so you can configure the action pojo in spring.

since version 2.5.0

Spring support for view pojos#

The scope should be @Scope("prototype")

  • Annotate your view pojo with the @Component spring annotation
  • Let your view pojo implement the ZIActiveView interface, process data in the beforeRendering method.
  • Instantiate your view pojo with ZIRenderService.createActiveView();

Spring support for ztemplates services#

If you don't like the ZTemplates.getXxxService() pattern you can now use autowiring ztemplates Services in action pojos.


@Component
@Scope("prototype")
@ZMatch("/index")
public class MyActionPojo
{
...
@Autowired
private ZIServletService servletService;

...
}

Enabling spring autowiring#

Add the following lines to your spring config to enable autowiring:


    <context:annotation-config />
    <context:spring-configured/>
    <context:component-scan base-package="org.ztemplates"/>

    <context:component-scan base-package="com.yourpath"/>

web.xml#

When using spring you have to add the following listeners and filters to web.xml, in this order (example is for Apache Velocity).


	<filter>
		<filter-name>SpringFilter</filter-name>
		<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
	</filter>	
	<filter>
		<filter-name>ZTemplatesFilter</filter-name>
		<filter-class>org.ztemplates.web.ZTemplatesFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>SpringFilter</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>ERROR</dispatcher>
	</filter-mapping>
	<filter-mapping>
		<filter-name>ZTemplatesFilter</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>ERROR</dispatcher>
	</filter-mapping>
....


	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<listener>
		<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
	</listener>
	<listener>
		<listener-class>org.ztemplates.web.ZTemplatesContextListener</listener-class>
	</listener>
	<listener>
		<listener-class>org.ztemplates.web.velocity.ZVelocityContextListener</listener-class>
	</listener>

Neuen Anhang hinzuf�gen

Du bist nicht autorisiert, Anh�nge zu dieser Seite hochzuladen.
« Diese Seite (Version-) wurde zuletzt am 29-Dez-2011 14:32 von gerdziegler.de ge�ndert.